/// <summary> /// Receives items and iteratively adds them to the pool.<br/> /// WARNING: These items are considered 'dead' but resurrectable so be sure not to hold on to their reference. /// </summary> /// <param name="target">The pool to give to.</param> /// <param name="item1">The first item to give up to the pool.</param> /// <param name="item2">The second item to give up to the pool.</param> /// <param name="items">The remaining items to give up to the pool.</param> public static void Give <T>(this IObjectPool <T> target, T item1, T item2, params T[] items) where T : class { if (target is null) { throw new ArgumentNullException(nameof(target)); } Contract.EndContractBlock(); target.Give(item1); target.Give(item2); target.Give(items); }
public void Dispose() { var i = _item; _item = null; if (i is null) { return; } _pool.Give(i); }
/// <summary> /// Receives items and iteratively adds them to the pool.<br/> /// WARNING: These items are considered 'dead' but resurrectable so be sure not to hold on to their reference. /// </summary> /// <param name="target">The pool to give to.</param> /// <param name="items">The items to give up to the pool.</param> public static void Give <T>(this IObjectPool <T> target, IEnumerable <T> items) where T : class { if (target is null) { throw new ArgumentNullException(nameof(target)); } Contract.EndContractBlock(); if (items is null) { return; } foreach (var i in items) { target.Give(i); } }
/// <inheritdoc cref="IObjectPool{T}.Give(T)"/> public static void Return <T>(this IObjectPool <T> pool, T item) where T : class => pool.Give(item);