Why won't DynamicProxy's interceptor get called for *each* virtual method call?

前端 未结 2 1331
孤街浪徒
孤街浪徒 2021-02-05 17:05

An example explains it best :

public interface IA { 
  void foo();
  void bar();
}

public class A : IA {
  public virtual void foo(){
    Console.Write(\"foo\")         


        
2条回答
  •  执笔经年
    2021-02-05 18:07

    You're using the method CreateInterfaceProxyWithTarget which instructs the proxy builder to create a proxy for the interface and forward the calls to the target object, so what you're seeing is what you've asked it to do.

    If you want the proxy to derive from your class then you'd need to use the CreateClassProxy method instead.

提交回复
热议问题