Snippet: Disposable class

property value
IDE Visual Studio
Language C#
Title Disposable class
Shortcut c_
Description class that implements IDisposable interface
Snippet Types Expansion
Namespaces System

Placeholders

Identifier Tooltip Default Value Editable Function Type Name
modifier Modifier(s) public yes
name Class name ClassName yes

Code

public class ClassName : IDisposable {
	private bool _disposed;

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

	protected virtual void Dispose(bool disposing) {
		if (!_disposed) {
			if (disposing) {
				throw new NotImplementedException();
			}

			_disposed = true;
		}
	}
}