Example #1
0
        static void Main(string[] args)
        {
            Subject realSub = new RealSubject();
            Subject proxy   = new Proxy(realSub);

            proxy.request();


            IGamePlayer player = new GamePlayer("张三");
            //然后再定义一个代练者
            IGamePlayer constraintProxy = player.getProxy();

            //开始打游戏,记下时间戳
            Console.WriteLine("开始时间是:" + DateTime.Now);
            constraintProxy.login("zhangSan", "password");
            //开始杀怪
            constraintProxy.killBoss();
            //升级
            constraintProxy.upgrade();
            //记录结束游戏时间
            Console.WriteLine("结束时间是:" + DateTime.Now);


            DynamicProxy      proxy1 = new DynamicProxy(typeof(DynamicGamePlayer), new DynamicGamePlayer("张三"));
            DynamicGamePlayer plane  = (DynamicGamePlayer)proxy1.GetTransparentProxy();

            plane.login("zhangSan", "password");
            plane.killBoss();
            plane.upgrade();
            Console.ReadLine();
        }
Example #2
0
 public DynamicProxy(Type t, DynamicGamePlayer plane) : base(t)
 {
     this.instance = plane;
 }