private IItemStore CreateItemStore(PoolingObjectsAccessMode mode, int capacity)
        {
            switch (mode)
            {
            case PoolingObjectsAccessMode.FIFO:
                return(new QueueStore(capacity));

            case PoolingObjectsAccessMode.LIFO:
                return(new StackStore(capacity));

            default:
                Debug.Assert(mode == PoolingObjectsAccessMode.Circular,
                             "Invalid AccessMode in CreateItemStore");
                return(new CircularStore(capacity));
            }
        }
        public ObjectsPool(int size, Func <ObjectsPool <T>, T> factory,
                           PoolingObjectsLoadingMode loadingMode, PoolingObjectsAccessMode accessMode)
        {
            if (size <= 0)
            {
                throw new ArgumentOutOfRangeException("size", size,
                                                      "Argument 'size' must be greater than zero.");
            }
            if (factory == null)
            {
                throw new ArgumentNullException("factory");
            }

            this.size        = size;
            this.factory     = factory;
            sync             = new Semaphore(size, size);
            this.loadingMode = loadingMode;
            this.itemStore   = CreateItemStore(accessMode, size);
            if (loadingMode == PoolingObjectsLoadingMode.Eager)
            {
                PreloadItems();
            }
        }