coding styles nullable
This commit is contained in:
@@ -1,49 +1,46 @@
|
||||
using System;
|
||||
|
||||
namespace Swan.Collections
|
||||
{
|
||||
namespace Swan.Collections {
|
||||
/// <summary>
|
||||
/// <para>Implements a collection of components that automatically disposes each component
|
||||
/// implementing <see cref="IDisposable"/>.</para>
|
||||
/// <para>Each component in the collection may be given a unique name for later retrieval.</para>
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of components in the collection.</typeparam>
|
||||
/// <seealso cref="ComponentCollection{T}" />
|
||||
/// <seealso cref="IComponentCollection{T}" />
|
||||
public class DisposableComponentCollection<T> : ComponentCollection<T>, IDisposable {
|
||||
/// <summary>
|
||||
/// <para>Implements a collection of components that automatically disposes each component
|
||||
/// implementing <see cref="IDisposable"/>.</para>
|
||||
/// <para>Each component in the collection may be given a unique name for later retrieval.</para>
|
||||
/// Finalizes an instance of the <see cref="DisposableComponentCollection{T}"/> class.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of components in the collection.</typeparam>
|
||||
/// <seealso cref="ComponentCollection{T}" />
|
||||
/// <seealso cref="IComponentCollection{T}" />
|
||||
public class DisposableComponentCollection<T> : ComponentCollection<T>, IDisposable
|
||||
{
|
||||
/// <summary>
|
||||
/// Finalizes an instance of the <see cref="DisposableComponentCollection{T}"/> class.
|
||||
/// </summary>
|
||||
~DisposableComponentCollection()
|
||||
{
|
||||
Dispose(false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Releases unmanaged and - optionally - managed resources.
|
||||
/// </summary>
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Releases unmanaged and - optionally - managed resources.
|
||||
/// </summary>
|
||||
/// <param name="disposing">
|
||||
/// <see langword="true"/> to release both managed and unmanaged resources; <see langword="true"/> to release only unmanaged resources.
|
||||
/// </param>
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
if (!disposing) return;
|
||||
|
||||
foreach (var component in this)
|
||||
{
|
||||
if (component is IDisposable disposable)
|
||||
disposable.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
~DisposableComponentCollection() {
|
||||
this.Dispose(false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Releases unmanaged and - optionally - managed resources.
|
||||
/// </summary>
|
||||
public void Dispose() {
|
||||
this.Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Releases unmanaged and - optionally - managed resources.
|
||||
/// </summary>
|
||||
/// <param name="disposing">
|
||||
/// <see langword="true"/> to release both managed and unmanaged resources; <see langword="true"/> to release only unmanaged resources.
|
||||
/// </param>
|
||||
protected virtual void Dispose(Boolean disposing) {
|
||||
if(!disposing) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach(T component in this) {
|
||||
if(component is IDisposable disposable) {
|
||||
disposable.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user