Intercept proxies allow for the interception of interface methods on an existing type. This is similar to what is done in DynamicProxy although based on the contract of the interface.
An intercept proxy is created with the following static method call:
using ProxyFoo;
public class SomeClass : IDisposable
{
void IDisposable.Dispose() { }
}
public class InterceptorClass : IDisposable
{
IDisposable _target;
public InterceptorClass( IDisposable target ) { }
public Dispose()
{
// Do something before
_target.Dispose();
// Do something after
}
}
var proxyType = ProxyModule.Default.GetTypeFromProxyClassDescriptor(
new ProxyClassDescriptor(
typeof(SomeClass),
new InterceptMixin(typeof(InterceptorClass))));
var result = (SomeClass)Activator.CreateInstance(proxyType);