Class DisposalTracker
- Namespace
- Xunit.Sdk
- Assembly
- xunit.v3.common.dll
Tracks disposable objects, and disposes them in the reverse order they were added to the tracker. Supports both IDisposable and IAsyncDisposable. You can either directly dispose this object (via DisposeAsync()), or you can enumerate the items contained inside of it (via TrackedObjects). Also supports hand-registering disposal actions via AddAction(Action) and AddAsyncAction(Func<ValueTask>). Note that an object implements both interfaces, this will only call DisposeAsync() and will not call Dispose().
public class DisposalTracker : IAsyncDisposable
- Inheritance
-
DisposalTracker
- Implements
- Inherited Members
Properties
- TrackedObjects
Gets a list of the items that are currently being tracked.
Methods
- Add(object?)
Add an object to be disposed. It may optionally support IDisposable and/or IAsyncDisposable.
- AddAction(Action)
Add an action to the list of things to be done during disposal.
- AddAsyncAction(Func<ValueTask>)
Add an action to the list of things to be done during disposal.
- AddRange(IEnumerable<object?>)
Add a collection of objects to be disposed. They may optionally support IDisposable and/or IAsyncDisposable.
- Clear()
Removes all objects from the disposal tracker.
- DisposeAsync()
Disposes all the objects that were added to the disposal tracker, in the reverse order of which they were added. For any object which implements both IDisposable and IAsyncDisposable we will favor DisposeAsync() and not call Dispose().