示例#1
0
        public T Take()
        {
            T         obj;
            IPoolable pooled = null;

            if (Pool.Count < 1)
            {
                switch (Behaviour)
                {
                case PoolBehavior.Grow:
                    obj    = CreateNewInstance();
                    pooled = obj as IPoolable;
                    pooled?.PoolInitialize();
                    break;

                case PoolBehavior.Fixed:
                    return(default);

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }
            else
            {
                obj = Pool.Take(Pool.Count - 1);
            }

            Active.Add(obj);
            pooled?.TakenFromPool();
            return(obj);
        }