Ejemplo n.º 1
0
        /// <summary>
        ///     Returns a pooled object of type T, if none are available another is created.
        /// </summary>
        /// <returns>An instance of T.</returns>
        internal T GetObject()
        {
#if NET_45
            T item;
            if (pool.TryTake(out item))
            {
                return(item);
            }
#else
            lock (pool)
            {
                if (pool.Count > 0)
                {
                    return(pool.Dequeue());
                }
            }
#endif
            return(objectFactory.Invoke());
        }