0
我努力学习面向方面编程的概念,我使用城堡项目动态代理为。请参阅我写的示例代码。拦截器拦截不C#,城堡动态代理
拦截器似乎没有拦截?或者我没有在我的控制台窗口中看到“在调用之前的内部拦截器,”和“内部拦截器,在调用之后”。请建议我在这里做错了什么?
class AOP
{
static void Main(string[] args)
{
ProxyGenerator generator = new ProxyGenerator();
actual logger = generator.CreateClassProxy<actual>(new proxyforactual());
logger.add(3, 2);
}
}
public class proxyforactual : IInterceptor
{
public void Intercept(IInvocation invocation)
{
Console.WriteLine("Inside interceptor, before the call");
invocation.Proceed();
Console.WriteLine("Inside interceptor, after the call");
}
}
public class actual
{
public int add(int x, int y)
{
Console.WriteLine("Inside method");
return x + y;
}
}