97 lines
2.0 KiB
C#
97 lines
2.0 KiB
C#
namespace View_by_Distance.FaceRecognitionDotNet.Models;
|
|
|
|
/// <summary>
|
|
/// Represents a class which has managed or unmanaged resources.
|
|
/// </summary>
|
|
public abstract class DisposableObject : IDisposable
|
|
{
|
|
|
|
#region Properties
|
|
|
|
/// <summary>
|
|
/// Gets a value indicating whether this instance has been disposed.
|
|
/// </summary>
|
|
/// <returns>true if this instance has been disposed; otherwise, false.</returns>
|
|
public bool IsDisposed
|
|
{
|
|
get;
|
|
private set;
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Methods
|
|
|
|
/// <summary>
|
|
/// If this object is disposed, then <see cref="ObjectDisposedException"/> is thrown.
|
|
/// </summary>
|
|
public void ThrowIfDisposed() =>
|
|
ObjectDisposedException.ThrowIf(IsDisposed, this);
|
|
|
|
internal void ThrowIfDisposed(string objectName)
|
|
{
|
|
#pragma warning disable CA1513
|
|
if (IsDisposed)
|
|
throw new ObjectDisposedException(objectName);
|
|
#pragma warning restore CA1513
|
|
}
|
|
|
|
#region Overrides
|
|
|
|
/// <summary>
|
|
/// Releases all managed resources.
|
|
/// </summary>
|
|
protected virtual void DisposeManaged()
|
|
{
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// Releases all unmanaged resources.
|
|
/// </summary>
|
|
protected virtual void DisposeUnmanaged()
|
|
{
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
#endregion
|
|
|
|
#region IDisposable Members
|
|
|
|
/// <summary>
|
|
/// Releases all resources used by this <see cref="DisposableObject"/>.
|
|
/// </summary>
|
|
public void Dispose()
|
|
{
|
|
GC.SuppressFinalize(this);
|
|
|
|
Dispose(true);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Releases all resources used by this <see cref="DisposableObject"/>.
|
|
/// </summary>
|
|
/// <param name="disposing">Indicate value whether <see cref="IDisposable.Dispose"/> method was called.</param>
|
|
private void Dispose(bool disposing)
|
|
{
|
|
if (IsDisposed)
|
|
{
|
|
return;
|
|
|
|
}
|
|
|
|
IsDisposed = true;
|
|
|
|
if (disposing)
|
|
|
|
DisposeManaged();
|
|
|
|
DisposeUnmanaged();
|
|
}
|
|
|
|
#endregion
|
|
|
|
} |