using Sarand.Net.Standard.Base.App; using Sarand.Net.Standard.Base.Utils; using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Diagnostics; using System.Text; namespace Sarand.Net.Standard.Base.Core { //======================================================================= public sealed class DisposableCollection : Collection, IDisposable where T : IDisposable { //------------------------------------------------------------------- // Construction. public DisposableCollection() : base() { } public DisposableCollection(IList items) : base(items) { } public void Dispose() { while (this.Count > 0) { // Extract the first item from the list. T item = this[0]; RemoveAt(0); try { if (item != null) item.Dispose(); } catch (Exception exc) { // Ignore exception. if (SacsSystem.DebugMode) { SaLogger.Debug(GetType().Name + ".Dispose " + ExceptionUtil.GetErrorStateMessage(exc)); Debugger.Break(); } } } } //------------------------------------------------------------------- /// /// Add item to the list. /// Null items are ignored. /// public new void Add (T item) { if (item != null) base.Add(item); } //------------------------------------------------------------------- } //======================================================================= }