using System; namespace Swan.Collections { /// /// Implements a collection of components that automatically disposes each component /// implementing . /// Each component in the collection may be given a unique name for later retrieval. /// /// The type of components in the collection. /// /// public class DisposableComponentCollection : ComponentCollection, IDisposable { /// /// Finalizes an instance of the class. /// ~DisposableComponentCollection() { Dispose(false); } /// /// Releases unmanaged and - optionally - managed resources. /// public void Dispose() { Dispose(true); GC.SuppressFinalize(this); } /// /// Releases unmanaged and - optionally - managed resources. /// /// /// to release both managed and unmanaged resources; to release only unmanaged resources. /// protected virtual void Dispose(bool disposing) { if (!disposing) return; foreach (var component in this) { if (component is IDisposable disposable) disposable.Dispose(); } } } }