public object Invoke(IMethodInvocation invocation) { ILoggeable target = invocation.This as ILoggeable; if (target != null && invocation.Method.DeclaringType != typeof(ILoggeable)) { target.Log("Invoking " + invocation.Method.Name); } return(invocation.Proceed()); }
public void MixinMethodsMustBeIntercepted() { String contents = "import AspectSharp.Tests.Classes in AspectSharp.Tests " + " " + " aspect McBrother for Author " + " " + " include Loggeable" + " include DummyPerson" + " " + " pointcut method|property(*)" + " advice(LogInvocationsInterceptor)" + " end" + " " + " end "; AspectEngineBuilder builder = new AspectLanguageEngineBuilder(contents); AspectEngine engine = builder.Build(); Author author = engine.WrapClass(typeof(Author)) as Author; Assert.IsNotNull(author); Assert.IsNotNull(author as ILoggeable); Assert.IsNotNull(author as IPerson); IPerson person = author as IPerson; person.Name = "McBilly"; Assert.AreEqual("McBilly", person.Name); ILoggeable log = author as ILoggeable; log.Log("Test"); String messages = log.GetLogMessages(); Assert.AreEqual("Invoking set_Name;Invoking get_Name;Test;", messages); }