// Collection of code snippets by Arne Vajhøj // (from articles on eksperten.dk / vajhoej.dk written sometime between 2004 and now) using System; using DotNetGuru.AspectDNG.Joinpoints; namespace OldStuff { // aspect public class Check { // advice: // around // pointcut: // any return type, any class, method name Divide, any arguments [AroundCall("* OldStuff.*::Divide(*)")] public static object MathCheck(MethodJoinPoint mjp) { object o = mjp[1]; if(o is int) { if((int)o == 0) { Console.WriteLine("AOP> About to divide by integer zero"); } } else if(o is double) { if((double)o == 0) { Console.WriteLine("AOP> About to divide by double zero"); } } else { throw new Exception("Unsupported data type in divide: " + o.GetType().FullName); } return mjp.Proceed(); } } }