static void Main(string[] args) { // 通过接口 ITest test1 = AopInterceptor.CreateProxyOfInterface <ITest, Test>(); // 通过类 Test test2 = AopInterceptor.CreateProxyOfClass <Test>(); test1.MyMethod(); test2.MyMethod(); // 指定构造函数 test2 = AopInterceptor.CreateProxyOfClass <Test>("aaa", "bbb"); test2.MyMethod(); Console.WriteLine("---"); // 非侵入式代理 TestNo test3 = AopInterceptor.CreateProxyOfType <TestNo>( new ProxyTypeBuilder(new Type[] { typeof(LogAttribute) }) .AddProxyMethod("LogAttribute", typeof(TestNo).GetMethod(nameof(TestNo.MyMethod))) .AddProxyMethod("LogAttribute", typeof(TestNo).GetProperty(nameof(TestNo.A)).GetSetMethod())); test3.MyMethod(); test3.A = "666"; Console.ReadKey(); }
public void CreateProxyOfClass() { // 通过类 Test test = AopInterceptor.CreateProxyOfClass <Test>(); test.MyMethod(); Assert.True(true); }
static void Main(string[] args) { //var name = DynamicProxy.GetAssemblyName(); //var ab = AssemblyBuilder.DefineDynamicAssembly(name, AssemblyBuilderAccess.RunAndSave); //var am = ab.DefineDynamicModule("AOPDebugModule", "AOPDebug.dll"); //DynamicProxy.SetSave(ab, am); //ab.Save("AopDebug.dll"); Test test = AopInterceptor.CreateProxyOfClass <Test>(); Console.WriteLine(test.Sum(1, 1)); Console.ReadKey(); }
public void TestGenerices() { // 通过类 var test = AopInterceptor.CreateProxyOfClass <Testgenerice3 <int, string, ApiCreateProxyTest> >(); Type[] types = test.MyTest(); bool isType = types[0] == typeof(int) && types[1] == typeof(string) && types[2] == typeof(ApiCreateProxyTest); Assert.True(isType); var test1 = AopInterceptor.CreateProxyOfClass <Testgenerice3 <object, AopInterceptor, Type> >(); types = test1.MyTest(); isType = types[0] == typeof(int) && types[1] == typeof(string) && types[2] == typeof(ApiCreateProxyTest); Assert.True(isType); }
public void TestGenerice() { // 通过类 var test = AopInterceptor.CreateProxyOfClass <Testgenerice1 <int> >(); bool isInt = test.MyTest() == typeof(int); Assert.True(isInt); var test1 = AopInterceptor.CreateProxyOfClass <Testgenerice1 <string> >(); bool isStr = test1.MyTest() == typeof(string); Assert.True(isStr); var test2 = AopInterceptor.CreateProxyOfClass <Testgenerice1 <ApiCreateProxyTest> >(); bool isobj = test2.MyTest() == typeof(ApiCreateProxyTest); Assert.True(isobj); }