Esempio n. 1
0
        private void MutiTest()
        {
            Log.L("Create a auto create  pool");
            MutiPool pool = new MutiPool();

            Log.L("Get an instance  A   from  pool");
            pool.SetPool(new MyPool2());
            IObject _obj = pool.Get <Obj_A>();

            //IObject _obj = pool.Get(typeof(Obj_A));

            Log.L($"the type of instance is {_obj.GetType()}");
            Log.L("Let's put the instance to pool");
            pool.Set(_obj);
            //pool.Set(typeof(Obj_A),_obj);

            Log.L("Get an instance  B from  pool");

            _obj = pool.Get <Obj_B>();
            Log.L($"the type of instance is {_obj.GetType()}");
            Log.L("Let's put the instance to pool");
            pool.Set(_obj);
        }
Esempio n. 2
0
        /// <summary>
        /// 基类对象池例子
        /// </summary>
        private void BaseTypePoolExample()
        {
            Log.L("");
            Log.L("————这个例子讲述如何使用基类对象池————");
            Log.L("创建一个继承BaseTypePool的基类对象池");
            MutiPool pool = new MutiPool();

            Log.L("从池中获取一个Obj_A类型的父类对象");
            IObject _obj = pool.Get <Obj_A>();

            Log.L($"取出的实例类型为{_obj.GetType()}");
            Log.L("一样使用Set方法将实例放回对象池");
            pool.Set(_obj);

            Log.L("从池中获取一个Obj_B类型的父类对象");
            _obj = pool.Get(typeof(Obj_B));
            Log.L($"取出的实例类型为{_obj.GetType()}");
            Log.L("使用Set方法将实例放回对象池 \n");
            pool.Set(_obj);

            Log.L("使用SetPool方法可以将父类对象池放入基类对象池中");
            pool.SetPool(new MyPool2());
        }