Better Things to do...like AOP
As Scott points out, there are much better things to do than talk about VB and C# all day... So, here is something a little more fun. Clemens isn't the only one that can use AOP with ServicedComponents anymore :-). I took a completely different approach and I am liking it a lot, since I seem to have bypassed a ton of the problems he was having. I'm not using MC++, so no sad Macs are going to pop up in your face, but I am debating just using all of Clemens cool, already written attribute code from his demo to test my implementation (I think I can match everything up to his interfaces with a few small tweaks). Still very early in the process right now though since I just started around 11:00 PM (it is 4:00 AM now and I can't seem to get to sleep now that it is up and running).
In any case, a little sample code to get your mouth watering:
public class TestInterceptionAttribute : Attribute, IPreprocessMethodCall
{
public void PreprocessMethodCall(MethodInfo method, object[] parameters)
{
System.Diagnostics.Trace.Write("Entering:"+method.Name+"\n");
}
}
class TestClass : System.EnterpriseServices.ServicedComponentpublic
{
[Activehead.AOP.TestInterception]
public virtual void Test(string s, string s2)
{
Console.WriteLine(s, s2);
}
}
And how does all this magic work? Good old IL, reflection, and emit. 100% pure managed code. I had to make some minor changes to get ServicedComponents working too (oh yah, I didn't mention that this AOP works with all .NET objects, not just ServicedComponents), but it wasn't too bad. 45 mins or so of extra hacking around was all it took (this whole thing would have gone a bit quicker if I had my nice IL book from MS Press on hand). Once I get everything tested I'll post some demo code.