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() {
this.Dispose(false);
}
///
/// Releases unmanaged and - optionally - managed resources.
///
public void Dispose() {
this.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(Boolean disposing) {
if(!disposing) {
return;
}
foreach(T component in this) {
if(component is IDisposable disposable) {
disposable.Dispose();
}
}
}
}
}