using System; namespace SharpMap.Base { /// /// /// public interface IDisposableEx : IDisposable { /// /// Gets whether this object was already disposed /// bool IsDisposed { get; } } /// /// Disposable object template /// /// /// This template was taken from phil haack's blog ( /// ) and further enhanced /// [Serializable] public abstract class DisposableObject : IDisposableEx { #region Implementation of IDisposable /// /// Finalizer /// ~DisposableObject() { ReleaseUnmanagedResources(); } /// /// Executes specific tasks that are concerned with freeing or initializing resources. /// public void Dispose() { Dispose(true); GC.SuppressFinalize(this); IsDisposed = true; } private void Dispose(bool disposing) { ReleaseUnmanagedResources(); if (disposing) ReleaseManagedResources(); } /// /// Releases unmanaged resources /// protected virtual void ReleaseUnmanagedResources() {} /// /// Releases managed resources /// protected virtual void ReleaseManagedResources() {} #endregion /// /// Method to check if this object has already been disposed /// protected void CheckDisposed() { if (IsDisposed) throw new ObjectDisposedException(GetType().Name); } [NonSerialized] private bool _isDisposed; /// /// Gets whether this object is disposed /// public bool IsDisposed { get { return _isDisposed; } private set { _isDisposed = value; } } } }