harrison314 / MassiveDynamicProxyGenerator

.Net library for generate proxy class instances
MIT License
13 stars 1 forks source link

Add method for IInvocation to call method on another context #17

Closed harrison314 closed 5 years ago

harrison314 commented 5 years ago

Add method for IInvocation to call method on another context:

interface IExample
{
   int Call(int x);
}

class ContextutalExample :IExample, IDisposable
{
    public int Call(int x)
    {
    return x+1;
    }
    public void Dispose()
    {
    }
}

ProxyGenerator generator = new ProxyGenerator();
InterceptorAdapter adapter = new InterceptorAdapter(invocation => {
  using(ContextutalExample instance = new ContextutalExample())
  {
    invocation.Process(instance);
  }
});

IExample proxy = generator.GenerateProxy<IExample>(adapter);
harrison314 commented 5 years ago

See MethodBuilder ImplementParentCallMethod(TypeBuilder typeBuilder, Type interfaceType, MethodInfo originalMethod)