using System.Threading.Tasks;
public static void Main()
var proxy = DispatchProxyAsync.Create<ITest, MyProxyAsync>();
Console.WriteLine($"Before call: a={a}, b={b}");
proxy.Func2(ref a, out b);
Console.WriteLine($"After call: a={a}, b={b}");
var proxy = DispatchProxy.Create<ITest, MyProxy>();
Console.WriteLine($"Before call: a={a}, b={b}");
proxy.Func2(ref a, out b);
Console.WriteLine($"After call: a={a}, b={b}");
class MyProxyAsync: DispatchProxyAsync
public override object Invoke(MethodInfo method, object[] args)
Console.WriteLine("Hello from proxy - call of " + method.Name);
for(int i = 0; i < args.Length;i++)
Console.WriteLine($" args[{i}] = {args[i]}");
public override async Task InvokeAsync(MethodInfo method, object[] args) => throw new NotSupportedException();
public override async Task<T> InvokeAsyncT<T>(MethodInfo method, object[] args) => throw new NotSupportedException();
class MyProxy: DispatchProxy
protected override object Invoke(MethodInfo method, object[] args)
Console.WriteLine("Hello from proxy - call of " + method.Name);
for(int i = 0; i < args.Length;i++)
Console.WriteLine($" args[{i}] = {args[i]}");
void Func2(ref int p1, out int p2);
void Func1(int p1, int p2);