Intercept only interface methods with DynamicProxy

一笑奈何 提交于 2019-12-04 19:13:20

If you want to create a proxy for the class, you need to use classproxy.

If you want to exclude certain members you have to use IProxyGenerationHook.

If you want your code to be agnostic to changes to members of interface/class like names signatures being added or removed - than make it so!

Simplest code I could think of is something like this:

private InterfaceMap interfaceMethods = typeof(YourClass).GetInterfaceMap(typeof(YourInterface));
public bool ShouldInterceptMethod(Type type, MethodInfo methodInfo)
{
   return Array.IndexOf(interfaceMethods.ClassMethods,methodInfo)!=-1;
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!