using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Diagnostics; namespace Microsoft.Research.DynamicDataDisplay.Common.Auxiliary { public static class ResourcePoolExtensions { /// /// Gets item from the pool, or creates new item if pool doesn't have more items. /// /// /// The pool. /// public static T GetOrCreate(this ResourcePool pool) where T : new() { T instance = pool.Get(); if (instance == null) { instance = new T(); } return instance; } /// /// Releases all items of given sequence into the pool. /// /// /// Pool, which will contain all released elements from the sequence. /// public static void ReleaseAll(this ResourcePool pool, IEnumerable sequence) { foreach (var item in sequence) { pool.Put(item); } } } }