Example #1
0
        public static T Pop(Func <T> generator = null)
        {
            T obj;


            lock (_instance)
            {
                if (generator == null)
                {
                    generator = _instance._generator;
                }


                if (_instance._queue.Count > 0)
                {
                    obj = _instance._queue.Dequeue();
                }
                else
                {
                    if (generator == null)
                    {
                        ConstructorInfo constructor = typeof(T).GetConstructor(
                            BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic
                            , null, new Type[0], null);
                        if (constructor != null)
                        {
                            obj = (T)constructor.Invoke(null);
                        }
                        else
                        {
                            throw new AegisException("No matches constructor on {0}.", typeof(T).Name);
                        }
                    }
                    else
                    {
                        obj = generator();
                    }
                }


                ObjectPoolManager.CallPopObject(obj, _instance._queue.Count());
            }


            return(obj);
        }
Example #2
0
 private ObjectPool()
 {
     ObjectPoolManager.Add(this);
 }