Click or drag to resize

Disposable Class

Helper methods to ease robust implementation of the IDisposable pattern.
Inheritance Hierarchy
SystemObject
  TomsToolbox.EssentialsDisposable

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 class Disposable

The Disposable type exposes the following members.

Methods
 NameDescription
Public methodStatic memberDispose If the specified object implements IDisposable, it will be disposed, else nothing is done.
Public methodStatic memberDisposeAll Calls Dispose(Object) for all objects in the list.
Public Extension MethodCode exampleReportNotDisposedObject 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.

Top
Events
 NameDescription
Public eventStatic memberNotDisposedObject Occurs when ReportNotDisposedObject(IDisposable) has been called, i.e. a not disposed object had been detected. Use this event to do some custom error handling, e.g. logging or throwing an exception. The Text will contain the name of the class of the object that was not disposed.
Top
See Also