使用方法:
class Program { static void Main(string[] args) { // var poxy = (targetInterface)ProxyGenerator.Create(typeof(targetInterface), new SamepleProxy()); // 或 //var poxy = (targetInterface)ProxyGenerator.Create(typeof(targetInterface), typeof(SamepleProxy)); // 或 var poxy = (targetInterface)ProxyGenerator.Create<targetInterface, SamepleProxy>(); poxy.Write("here is invoked by coreproxy"); } } public class SamepleProxy : IInterceptor { public object Intercept(object target, MethodInfo method, object[] parameters) { Console.WriteLine(parameters[0]); return null; } } public interface targetInterface { void Write(string writesome); }总结一下就是,微软爸爸给我们的这个轮子还是即轻便又很好用的。
本文的实例代码可以在我的github上找到:https://github.com/ElderJames/CoreProxy