// Collection of code snippets by Arne Vajhøj // (from articles on eksperten.dk / vajhoej.dk written sometime between 2004 and now) using System; using Vajhoej.StaticWeaver; namespace MyStuff { // aspect [Aspect] public class Trace { // pointcut: // any return type, class MyStuff.IntMath, any method name, any arguments // any return type, class MyStuff.DoubleMath, any method name, any arguments [Pointcut(Signature="* MyStuff.IntMath::*(*) || * MyStuff.DoubleMath::*(*)")] public static void MathTrace() { } // advice: // before [BeforeCallAdvice(Pointcut="MathTrace")] public static void Enter(MethodJoinpoint mjp) { Console.WriteLine("AOP> Enter " + mjp); } // advice: // after [AfterCallAdvice(Pointcut="MathTrace")] public static void Leave(MethodJoinpoint mjp) { Console.WriteLine("AOP> Exit " + mjp); } } }