コード例 #1
0
        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();
        }
コード例 #2
0
        public void CreateProxyOfInterface()
        {
            // 通过接口
            ITest test = AopInterceptor.CreateProxyOfInterface <ITest, Test>();

            test.MyMethod();
            Assert.True(true);
        }