private static ObjectPool <T> Create(ObjectPoolLoadMode mode, int minSize, int maxSize, params object[] constructorParameters) { if (minSize < 0) { throw new ArgumentException("minSize cannot be less than zero", nameof(minSize)); } if (maxSize < 0) { throw new ArgumentException("maxSize cannot be less than zero", nameof(maxSize)); } if (minSize > maxSize) { throw new ArgumentOutOfRangeException("minSize greater than maxSize zero", nameof(minSize)); } Type gType = typeof(T); List <Type> objectTypes = new List <Type>(constructorParameters.Length); foreach (object obj in constructorParameters) { objectTypes.Add(obj.GetType()); } Queue <T> items = new Queue <T>(maxSize); int currentSize = mode == ObjectPoolLoadMode.Eager ? maxSize : minSize; for (int i = 0; i < currentSize; i++) { items.Enqueue(CreateObject(constructorParameters)); } return(new ObjectPool <T>(mode, maxSize, currentSize, items, constructorParameters)); }
private ObjectPool(ObjectPoolLoadMode loadMode, int maxSize, int currentSize, Queue <T> items, object[] constructorParameters) { _maxSize = maxSize; _currentSize = currentSize; _items = items; _constructorParameters = constructorParameters; _loadMode = loadMode; }