A Lightweight Class Library for Generating Dynamic Proxy Objects Based on Emit.
publicclassCalculate:ICalculate{publicvirtualintAdd(inta,intb){returna+b;}}publicinterfaceICalculate{intAdd(inta,intb);}publicclassLogInterceptor:IInterceptor{publicvoidIntercept(IInvocationinvocation){Debug.WriteLine("LogInterceptor pre....");invocation.Proceed();Debug.WriteLine("LogInterceptor post....");}}varbuilder=newDefaultProxyBuilder(newModuleScope());varproxyGenerator=newDefaultProxyGenerator(builder);//Using a public parameterless constructorvarcalculator=proxyGenerator.CreateInterfaceProxy<ICalculate,Calculate>(newLogInterceptor());//or Specify Constructorcalculator=proxyGenerator.CreateInterfaceProxy<ICalculate,Calculate>(newobject[]{"test"},newLogInterceptor());//or with target calculator=proxyGenerator.CreateInterfaceProxyWithTarget<ICalculate,Calculate>(newCalculate(),newLogInterceptor());calculator.Add(1,3);//Ignore a method's proxy//Add the Ignore attribute on the method[Ignore]publicintMultiply(inta,intb){returna*b;}TODO
- Dependency Injection
- Code optimization
PS: This project draws on some of the code design from castle. dynamic. We hope everyone can point out more issues that need improvement, learn together, and improve together.