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) Version: 2.21.0+44d18b541fc9419ec3c549350a832394661b2a4d
XMLNS for XAML: Not mapped to an xmlns.
Syntax
public static void ReportNotDisposedObject(
	this IDisposable obj
)

Parameters

obj  IDisposable
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).
Example
Implement IDisposable like this:

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

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