1. Mohamad Amin Valinejad
  2. SharpHammer

Source

SharpHammer / SharpHammer / DisposableBase.cs

using System;

namespace SharpHammer
{
	public abstract class DisposableBase : IDisposable
	{
		private bool _disposed = false;

		~DisposableBase()
		{
			Dispose();
		}

		public void Dispose()
		{
			Dispose(true);
			GC.SuppressFinalize(this);
		}

		protected abstract void OnDispose(bool managed);

		private void Dispose(bool disposing)
		{
			if (_disposed)
				return;
			_disposed = true;
			if (disposing)
				OnDispose(true);
			OnDispose(false);
		}
	}
}