Click or drag to resize

DisposableReportNotDisposedObject Method

Handle reporting of a not disposed object.

Using this pattern is a good practice to avoid code where disposable objects get never disposed.

Calling this method will raise the NotDisposedObject event if any event handler is attached; otherwise it will throw an InvalidOperationException if a debugger is attached. If the application does not run in a debugger and no event handler is attached, calling this method does nothing.

Namespace:  TomsToolbox.Essentials
Assembly:  TomsToolbox.Essentials (in TomsToolbox.Essentials.dll)
Syntax
public static void ReportNotDisposedObject(
	this IDisposable obj
)

Parameters

obj
Type: SystemIDisposable
The object for which to report the missing dispose call.

Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type IDisposable. When you use instance method syntax to call this method, omit the first parameter. For more information, see Extension Methods (Visual Basic) or Extension Methods (C# Programming Guide).
Examples
Implement IDisposable like this:

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

~MyClass()
{
    this.ReportNotDisposedObject();
}
See Also