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 IInterceptorSelector to 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
internal class Program
{
private static void Main(string[] args)
{
var pg = new ProxyGenerator();
var options = new ProxyGenerationOptions();
options.Selector = new Selector();
var test = pg.CreateClassProxy<Foo>(options, new InterceptorA(), new InterceptorB());
test.InterceptedByA();
test.InterceptedByB();
}
}
public class Foo
{
public virtual void InterceptedByA() { Console.WriteLine("A"); }
public virtual void InterceptedByB() { Console.WriteLine("B"); }
}
public class Selector : IInterceptorSelector
{
public IInterceptor[] SelectInterceptors(Type type, System.Reflection.MethodInfo method, IInterceptor[] interceptors)
{
return interceptors.Where(s => s.GetType().Name.Replace("or", "edBy") == method.Name).ToArray();
}
}
public class InterceptorA : IInterceptor
{
public void Intercept(IInvocation invocation)
{
Console.WriteLine("InterceptorA");
invocation.Proceed();
}
}
public class InterceptorB : IInterceptor
{
public void Intercept(IInvocation invocation)
{
Console.WriteLine("InterceptorB");
invocation.Proceed();
}
}