Let's say I have a type like this:
public class Foo
{
public virtual void InterceptedByA() { }
public virtual void InterceptedByB() { }
}
I have two selectors named InterceptorA and InterceptorB. I want to use multiple IProxyGenerationHook implementations to ensure they only intercept their own methods. ProxyGenerator class accepts an array of interceptors but I can only use single IProxyGenerationHook instance in ProxyGenerationOptions constructor:
var options = new ProxyGenerationOptions(new ProxyGenerationHookForA());
Is there a way to use multiple IProxyGenerationHook implementations for creating a proxy?
The IProxyGenerationHook is used at proxy-ing time only once for the object being proxy-ed. If you want fine-grained control about which interceptors are used for a method you should use the IInterceptorSelector
Here is a (very stupid) example that could help you see how you could use the
IInterceptorSelectorto match the methods called. Of course you wouldn't rely on the method names in order to match the selectors but this is left as an exercice