Esempio n. 1
0
        /// <summary>
        /// 动态代理
        /// </summary>
        static void DynamicProxyByRemoting()
        {
            Console.WriteLine($"动态代理 Remoting{Environment.NewLine}-------------------------------------------");

            DynamicAction action = new DynamicAction();

            action.BeforeActionList.Add(new Action(() => Console.WriteLine("收取中介费")));
            action.BeforeActionList.Add(new Action(() => Console.WriteLine("办理各种过户手术")));
            action.AfterActionList.Add(new Action(() => Console.WriteLine("交易完成")));

            ProxyFactory <HouseA> factory = new ProxyFactory <HouseA>();
            HouseA houseA = factory.CreateProxy();

            houseA.Buy();
            Console.WriteLine("-----------------");

            houseA.Name = "房屋AAAAAAAAAAA";
            HouseA houseAA = factory.CreateProxy(houseA, action);

            houseAA.Buy();
            Console.WriteLine("-----------------");

            ProxyFactory <HouseB> factoryB = new ProxyFactory <HouseB>();
            HouseB houseB = factoryB.CreateProxy(action);

            houseB.Buy();
            Console.ReadKey();
        }
Esempio n. 2
0
        /// <summary>
        /// 动态代理
        /// </summary>
        static void DynamicProxyByCastle()
        {
            Console.WriteLine($"动态代理 Castle{Environment.NewLine}-------------------------------------------");

            ProxyGenerator generator = new ProxyGenerator();
            HouseA         houseA    = generator.CreateClassProxy <HouseA>(new ClassInterceptor());

            houseA.Buy();
            Console.ReadKey();
        }