Skip to content

ReferenceAPI map

API map

Every public type and member, with its signature, what it does and the page that explains it.

This page lists every public type and member of the one package NCode.Disposables, whose types are all in the namespace NCode.Disposables. The gate fails when this map and the package’s PublicAPI.Shipped.txt differ, so every member that ships has an entry.

MemberSignatureWhat it doesExplained on
Disposablepublic static class DisposableThe factory for the synchronous disposables: each member returns the concrete type it creates./start/which-disposable/
Disposable.Emptypublic static DisposableEmpty Empty { get; }The shared instance whose Dispose does nothing, DisposableEmpty.Singleton./guides/run-code-on-dispose/
Disposable.Createpublic static DisposableAction Create(Action action)public static DisposableAction Create<T>(Action<T> action, T arg)public static DisposableAction Create<TResult>(Func<TResult> action)public static DisposableAction Create<T, TResult>(Func<T, TResult> action, T arg)Runs the action on the first Dispose only, even when several threads dispose at once. Overloads pass up to eight arguments, and a Func overload discards its result./guides/run-code-on-dispose/
Disposable.CreateRepeatablepublic static DisposableAction CreateRepeatable(Action action)Runs the action on every Dispose call./guides/run-code-on-dispose/
Disposable.CreateValuepublic static ValueDisposable<TState> CreateValue<TState>(Action<TState> action, TState state)A struct that allocates nothing and runs the action with its state on every dispose of every copy./guides/run-code-on-dispose/
Disposable.Aggregatepublic static DisposableAggregate Aggregate(IDisposable? disposable)public static DisposableAggregate Aggregate()Holds one resource you can replace; replacing it does not dispose the old one./guides/hold-a-changing-resource/
Disposable.Serialpublic static DisposableSerial Serial()public static DisposableSerial Serial(IDisposable? disposable)Holds one resource and disposes it when another replaces it./guides/hold-a-changing-resource/
Disposable.SingleAssignmentpublic static DisposableSingleAssignment SingleAssignment()Takes one resource, once; a second assignment throws InvalidOperationException./guides/hold-a-changing-resource/
Disposable.Guardpublic static DisposableGuard<T> Guard<T>(T value) where T : IDisposableDisposes the value when the scope ends unless Release() hands it on first./guides/hand-on-ownership/
Disposable.Cancellationpublic static DisposableCancellation Cancellation()public static DisposableCancellation Cancellation(CancellationTokenSource source)Cancels a token on dispose; a source it created is then disposed, a source you pass in is not./guides/cancel-on-dispose/
Disposable.Flagpublic static DisposableFlag Flag()Records only that it was disposed, in IsDisposed./concepts/disposal-status/
Disposable.Collectionpublic static DisposableCollection Collection(params IDisposable[] collection)public static DisposableCollection Collection(IEnumerable<IDisposable> collection)Disposes its items in reverse order on the first Dispose; one failure is rethrown, several as one AggregateException./guides/dispose-many-resources/
Disposable.CollectionIgnoringExceptionspublic static DisposableCollection CollectionIgnoringExceptions(params IDisposable[] collection)public static DisposableCollection CollectionIgnoringExceptions(IEnumerable<IDisposable> collection)As Collection, but ignores the exceptions its items throw./guides/dispose-many-resources/
Disposable.Contextpublic static DisposableContext Context(IDisposable disposable, SynchronizationContext context)Disposes the resource once on the context, through Send, and returns once it is disposed./guides/dispose-on-a-context/
Disposable.PostingContextpublic static DisposableContext PostingContext(IDisposable disposable, SynchronizationContext context)Disposes the resource once on the context, through Post, and returns at once./guides/dispose-on-a-context/
Disposable.Sharedpublic static SharedReferenceLease<T> Shared<T>(T value) where T : IDisposablepublic static SharedReferenceLease<T> Shared<T>(T value, Action<T> onRelease)Calls SharedReference.Create: the first lease on a reference-counted resource./guides/share-a-resource/
AsyncDisposablepublic static class AsyncDisposableThe factory for the asynchronous disposables: each member returns the concrete type it creates./start/which-disposable/
AsyncDisposable.Emptypublic static AsyncDisposableEmpty Empty { get; }The shared instance whose DisposeAsync does nothing, AsyncDisposableEmpty.Singleton./guides/run-code-on-dispose/
AsyncDisposable.Createpublic static AsyncDisposableAction Create(Func<ValueTask> action)public static AsyncDisposableAction Create(Action action)public static AsyncDisposableAction Create<T>(Func<T, ValueTask> action, T arg)public static AsyncDisposableAction Create<T1, T2>(Func<T1, T2, ValueTask> action, T1 arg1, T2 arg2)Runs the action on the first DisposeAsync only. An Action runs synchronously, and the state overloads take up to eight arguments, as Func<…, ValueTask> only./guides/run-code-on-dispose/
AsyncDisposable.CreateRepeatablepublic static AsyncDisposableAction CreateRepeatable(Func<ValueTask> action)public static AsyncDisposableAction CreateRepeatable(Action action)Runs the action on every DisposeAsync call./guides/run-code-on-dispose/
AsyncDisposable.CreateValuepublic static AsyncValueDisposable<TState> CreateValue<TState>(Func<TState, ValueTask> action, TState state)A struct that allocates nothing and runs the action with its state on every dispose of every copy./guides/run-code-on-dispose/
AsyncDisposable.Adaptpublic static AsyncDisposableAdapter Adapt(IDisposable disposable)An IAsyncDisposable that disposes the IDisposable once; null throws ArgumentNullException./guides/bridge-sync-and-async/
AsyncDisposable.AdaptRepeatablepublic static AsyncDisposableAdapter AdaptRepeatable(IDisposable disposable)As Adapt, but disposes the resource on every call./guides/bridge-sync-and-async/
AsyncDisposable.Aggregatepublic static AsyncDisposableAggregate Aggregate(IAsyncDisposable? disposable)public static AsyncDisposableAggregate Aggregate()Holds one resource you can replace. After disposal its setter throws ObjectDisposedException, and SetDisposableAsync disposes the resource./guides/hold-a-changing-resource/
AsyncDisposable.Serialpublic static AsyncDisposableSerial Serial()public static AsyncDisposableSerial Serial(IAsyncDisposable? disposable)Holds one resource and disposes it when SetDisposableAsync replaces it./guides/hold-a-changing-resource/
AsyncDisposable.SingleAssignmentpublic static AsyncDisposableSingleAssignment SingleAssignment()Takes one resource through SetDisposableAsync, once./guides/hold-a-changing-resource/
AsyncDisposable.Guardpublic static AsyncDisposableGuard<T> Guard<T>(T value) where T : IAsyncDisposableDisposes the value asynchronously when the scope ends unless Release() hands it on first./guides/hand-on-ownership/
AsyncDisposable.Cancellationpublic static AsyncDisposableCancellation Cancellation()public static AsyncDisposableCancellation Cancellation(CancellationTokenSource source)Cancels a token on dispose with CancelAsync; a source it created is then disposed./guides/cancel-on-dispose/
AsyncDisposable.Collectionpublic static AsyncDisposableCollection Collection(params IAsyncDisposable[] collection)public static AsyncDisposableCollection Collection(IEnumerable<IAsyncDisposable> collection)Disposes its items in reverse order with DisposeAsync. After disposal Add throws ObjectDisposedException, and AddAsync disposes the item./guides/dispose-many-resources/
AsyncDisposable.CollectionIgnoringExceptionspublic static AsyncDisposableCollection CollectionIgnoringExceptions(params IAsyncDisposable[] collection)public static AsyncDisposableCollection CollectionIgnoringExceptions(IEnumerable<IAsyncDisposable> collection)As Collection, but ignores the exceptions its items throw./guides/dispose-many-resources/
AsyncDisposable.Contextpublic static AsyncDisposableContext Context(IAsyncDisposable disposable, SynchronizationContext context)Posts the disposal to the context and completes once it has run there./guides/dispose-on-a-context/
AsyncDisposable.Sharedpublic static AsyncSharedReferenceLease<T> Shared<T>(T value) where T : IAsyncDisposablepublic static AsyncSharedReferenceLease<T> Shared<T>(T value, Func<T, ValueTask> onRelease)Calls AsyncSharedReference.Create: the first lease on a reference-counted resource./guides/share-a-resource/
SharedReferencepublic static class SharedReferenceCreates a reference-counted owner and returns its first lease./guides/share-a-resource/
SharedReference.Createpublic static SharedReferenceLease<T> Create<T>(T value) where T : IDisposablepublic static SharedReferenceLease<T> Create<T>(T value, Action<T> onRelease)The first lease. Disposing the last lease disposes the value, or runs onRelease, once./guides/share-a-resource/
AsyncSharedReferencepublic static class AsyncSharedReferenceCreates a reference-counted owner and returns its first lease, synchronously./guides/share-a-resource/
AsyncSharedReference.Createpublic static AsyncSharedReferenceLease<T> Create<T>(T value) where T : IAsyncDisposablepublic static AsyncSharedReferenceLease<T> Create<T>(T value, Func<T, ValueTask> onRelease)The first lease. Disposing the last lease disposes the value with DisposeAsync, or runs onRelease, once./guides/share-a-resource/
MemberSignatureWhat it doesExplained on
DisposableActionpublic sealed class DisposableAction(Action action) : IDisposable, IDisposalStatuspublic bool IsDisposed { get; }public void Dispose()The disposable Create and CreateRepeatable return: runs its action once, or on every call from CreateRepeatable. IsDisposed is true once disposal has started./guides/run-code-on-dispose/
AsyncDisposableActionpublic sealed class AsyncDisposableAction(Func<ValueTask> action) : IAsyncDisposable, IDisposalStatuspublic bool IsDisposed { get; }public ValueTask DisposeAsync()As DisposableAction, for DisposeAsync./guides/run-code-on-dispose/
ValueDisposable<TState>public readonly struct ValueDisposable<TState>(Action<TState> action, TState state) : IDisposablepublic void Dispose()A readonly struct that runs its action with its state on every dispose of every copy; default does nothing. The lock scopes are this type./concepts/once-or-every-time/
AsyncValueDisposable<TState>public readonly struct AsyncValueDisposable<TState>(Func<TState, ValueTask> action, TState state) : IAsyncDisposablepublic ValueTask DisposeAsync()As ValueDisposable<TState>, for DisposeAsync./concepts/once-or-every-time/
DisposableEmptypublic sealed class DisposableEmpty : IDisposablepublic static DisposableEmpty Singleton { get; }public void Dispose()Does nothing; Singleton is the instance Disposable.Empty returns./guides/run-code-on-dispose/
AsyncDisposableEmptypublic sealed class AsyncDisposableEmpty : IAsyncDisposablepublic static AsyncDisposableEmpty Singleton { get; }public ValueTask DisposeAsync()Does nothing; Singleton is the instance AsyncDisposable.Empty returns./guides/run-code-on-dispose/
MemberSignatureWhat it doesExplained on
DisposableAggregatepublic sealed class DisposableAggregate : IDisposable, IDisposalStatuspublic bool IsDisposed { get; }public DisposableAggregate()public DisposableAggregate(IDisposable? disposable)public void Dispose()public IDisposable? Disposable { get; set; }Holds one resource in Disposable, swapped atomically. Disposing the aggregate disposes the resource it holds; replacing it does not. After disposal Disposable reads null and disposes a resource set on it./guides/hold-a-changing-resource/
AsyncDisposableAggregatepublic sealed class AsyncDisposableAggregate : IAsyncDisposable, IDisposalStatuspublic bool IsDisposed { get; }public AsyncDisposableAggregate()public AsyncDisposableAggregate(IAsyncDisposable? disposable)public ValueTask DisposeAsync()public IAsyncDisposable? Disposable { get; set; }public ValueTask SetDisposableAsync(IAsyncDisposable? disposable)As DisposableAggregate, for IAsyncDisposable. After disposal its setter throws ObjectDisposedException, and SetDisposableAsync disposes the resource./guides/hold-a-changing-resource/
DisposableSerialpublic sealed class DisposableSerial : IDisposable, IDisposalStatuspublic bool IsDisposed { get; }public DisposableSerial()public DisposableSerial(IDisposable? disposable)public void Dispose()public IDisposable? Disposable { get; set; }Holds one resource in Disposable and disposes it when another replaces it. Setting the instance it already holds does nothing./guides/hold-a-changing-resource/
AsyncDisposableSerialpublic sealed class AsyncDisposableSerial : IAsyncDisposable, IDisposalStatuspublic bool IsDisposed { get; }public AsyncDisposableSerial()public AsyncDisposableSerial(IAsyncDisposable? disposable)public ValueTask DisposeAsync()public IAsyncDisposable? Disposable { get; }public ValueTask SetDisposableAsync(IAsyncDisposable? disposable)As DisposableSerial, through SetDisposableAsync./guides/hold-a-changing-resource/
DisposableSingleAssignmentpublic sealed class DisposableSingleAssignment : IDisposable, IDisposalStatuspublic bool IsDisposed { get; }public bool IsAssigned { get; }public void Dispose()public IDisposable? Disposable { get; set; }Takes one non-null resource in Disposable, once: a second assignment throws InvalidOperationException. A resource assigned after disposal is disposed at once./guides/hold-a-changing-resource/
AsyncDisposableSingleAssignmentpublic sealed class AsyncDisposableSingleAssignment : IAsyncDisposable, IDisposalStatuspublic bool IsDisposed { get; }public bool IsAssigned { get; }public ValueTask DisposeAsync()public IAsyncDisposable? Disposable { get; }public ValueTask SetDisposableAsync(IAsyncDisposable disposable)As DisposableSingleAssignment, through SetDisposableAsync./guides/hold-a-changing-resource/
DisposableGuard<T>public sealed class DisposableGuard<T>(T value) : IDisposable, IDisposalStatus where T : IDisposablepublic T Value { get; }public bool IsReleased { get; }public bool IsDisposed { get; }public T Release()public void Dispose()Disposes Value on Dispose unless Release() returned it first. A second Release() throws InvalidOperationException, and Release() after Dispose throws ObjectDisposedException./guides/hand-on-ownership/
AsyncDisposableGuard<T>public sealed class AsyncDisposableGuard<T>(T value) : IAsyncDisposable, IDisposalStatus where T : IAsyncDisposablepublic T Value { get; }public bool IsReleased { get; }public bool IsDisposed { get; }public T Release()public ValueTask DisposeAsync()As DisposableGuard<T>, for an IAsyncDisposable./guides/hand-on-ownership/
DisposableCollectionpublic sealed class DisposableCollection : IDisposable, ICollection<IDisposable>, IDisposalStatuspublic DisposableCollection()public DisposableCollection(IEnumerable<IDisposable> collection)public void Dispose()public bool IsDisposed { get; }public bool IsReadOnly { get; }public int Count { get; }public void Add(IDisposable item)public bool Remove(IDisposable item)public void Clear()public bool Contains(IDisposable item)public void CopyTo(IDisposable[] array, int arrayIndex)public IEnumerator<IDisposable> GetEnumerator()An ICollection<IDisposable> that disposes its items in reverse order on its first Dispose. Remove and Clear don't dispose, and an item added after disposal is disposed at once./guides/dispose-many-resources/
AsyncDisposableCollectionpublic sealed class AsyncDisposableCollection : IAsyncDisposable, ICollection<IAsyncDisposable>, IDisposalStatuspublic AsyncDisposableCollection()public AsyncDisposableCollection(IEnumerable<IAsyncDisposable> collection)public ValueTask DisposeAsync()public bool IsDisposed { get; }public bool IsReadOnly { get; }public int Count { get; }public void Add(IAsyncDisposable item)public ValueTask AddAsync(IAsyncDisposable item)public bool Remove(IAsyncDisposable item)public void Clear()public bool Contains(IAsyncDisposable item)public void CopyTo(IAsyncDisposable[] array, int arrayIndex)public IEnumerator<IAsyncDisposable> GetEnumerator()An ICollection<IAsyncDisposable> that disposes its items in reverse order with DisposeAsync. After disposal Add throws ObjectDisposedException, and AddAsync disposes the item./guides/dispose-many-resources/
MemberSignatureWhat it doesExplained on
SharedReferenceLease<T>public readonly struct SharedReferenceLease<T>(ISharedReferenceOwner<T> owner) : IDisposablepublic bool IsActive { get; }public T Value { get; }public SharedReferenceLease<T> AddReference()public bool TryAddReference(out SharedReferenceLease<T> reference)public void Dispose()A readonly struct lease: Value, IsActive, AddReference, TryAddReference, and Dispose, which releases one reference. A copy is the same lease, and a default lease's Value throws InvalidOperationException./guides/share-a-resource/
AsyncSharedReferenceLease<T>public readonly struct AsyncSharedReferenceLease<T>(IAsyncSharedReferenceOwner<T> owner) : IAsyncDisposablepublic bool IsActive { get; }public T Value { get; }public AsyncSharedReferenceLease<T> AddReference()public bool TryAddReference(out AsyncSharedReferenceLease<T> reference)public ValueTask DisposeAsync()As SharedReferenceLease<T>, released with DisposeAsync./guides/share-a-resource/
SharedReferenceOwner<T>public sealed class SharedReferenceOwner<T>(T value, Action<T> onRelease) : ISharedReferenceOwner<T>public T Value { get; }public SharedReferenceLease<T> AddReference()public bool TryAddReference(out SharedReferenceLease<T> reference)public int ReleaseReference()The reference count behind the leases, starting at 1. The release action runs once, on the thread that releases the last lease; after that AddReference and Value throw ObjectDisposedException./guides/share-a-resource/
AsyncSharedReferenceOwner<T>public sealed class AsyncSharedReferenceOwner<T>(T value, Func<T, ValueTask> onRelease) : IAsyncSharedReferenceOwner<T>public T Value { get; }public AsyncSharedReferenceLease<T> AddReference()public bool TryAddReference(out AsyncSharedReferenceLease<T> reference)public ValueTask<int> ReleaseReferenceAsync()public int UnsafeReleaseReference()As SharedReferenceOwner<T>, released with ReleaseReferenceAsync./guides/share-a-resource/
ISharedReferenceOwner<T>public interface ISharedReferenceOwner<T>T Value { get; }SharedReferenceLease<T> AddReference()bool TryAddReference(out SharedReferenceLease<T> reference)int ReleaseReference()The owner a SharedReferenceLease<T> releases through./guides/share-a-resource/
IAsyncSharedReferenceOwner<T>public interface IAsyncSharedReferenceOwner<T>T Value { get; }AsyncSharedReferenceLease<T> AddReference()bool TryAddReference(out AsyncSharedReferenceLease<T> reference)ValueTask<int> ReleaseReferenceAsync()The owner an AsyncSharedReferenceLease<T> releases through./guides/share-a-resource/
MemberSignatureWhat it doesExplained on
DisposableCancellationpublic sealed class DisposableCancellation : IDisposable, IDisposalStatuspublic CancellationToken Token { get; }public DisposableCancellation()public DisposableCancellation(CancellationTokenSource source)public bool IsDisposed { get; }public void Dispose()Cancels Token on its first Dispose, then disposes the source it created; a source passed to its constructor is cancelled, not disposed. A token callback that throws surfaces as AggregateException./guides/cancel-on-dispose/
AsyncDisposableCancellationpublic sealed class AsyncDisposableCancellation : IAsyncDisposable, IDisposalStatuspublic CancellationToken Token { get; }public AsyncDisposableCancellation()public AsyncDisposableCancellation(CancellationTokenSource source)public bool IsDisposed { get; }public ValueTask DisposeAsync()As DisposableCancellation, cancelling with CancelAsync./guides/cancel-on-dispose/
DisposableContextpublic sealed class DisposableContext(IDisposable disposable, SynchronizationContext context) : IDisposable, IDisposalStatuspublic bool IsDisposed { get; }public void Dispose()Disposes a resource once on a SynchronizationContext, through Send, or through Post from Disposable.PostingContext, between OperationStarted and OperationCompleted./guides/dispose-on-a-context/
AsyncDisposableContextpublic sealed class AsyncDisposableContext(IAsyncDisposable disposable, SynchronizationContext context) : IAsyncDisposable, IDisposalStatuspublic bool IsDisposed { get; }public ValueTask DisposeAsync()Posts the DisposeAsync of a resource to a SynchronizationContext and completes once it has run there./guides/dispose-on-a-context/
AsyncDisposableAdapterpublic sealed class AsyncDisposableAdapter(IDisposable disposable) : IAsyncDisposable, IDisposalStatuspublic bool IsDisposed { get; }public ValueTask DisposeAsync()An IAsyncDisposable over an IDisposable, disposing it once, or on every call from AdaptRepeatable./guides/bridge-sync-and-async/
DisposableFlagpublic sealed class DisposableFlag : IDisposable, IDisposalStatuspublic bool IsDisposed { get; }public void Dispose()Records only that it was disposed./concepts/disposal-status/
IDisposalStatuspublic interface IDisposalStatusbool IsDisposed { get; }IsDisposed: true once disposal has started. Every disposable class that keeps disposal state implements it; the structs don't./concepts/disposal-status/
MemberSignatureWhat it doesExplained on
DisposableExtensionspublic static class DisposableExtensionspublic static ValueTask DisposeAsyncIfAvailable(this IDisposable? disposable)public static SharedReferenceLease<T> AsSharedReference<T>(this T value) where T : IDisposablepublic static void DisposeAll(this IEnumerable<object?> collection)public static void DisposeAllIgnoringExceptions(this IEnumerable<object?> collection)DisposeAll() and DisposeAllIgnoringExceptions() dispose each IDisposable of a list in reverse order; DisposeAsyncIfAvailable() prefers DisposeAsync; AsSharedReference() calls SharedReference.Create./guides/dispose-many-resources/
AsyncDisposableExtensionspublic static class AsyncDisposableExtensionspublic static AsyncSharedReferenceLease<T> AsAsyncSharedReference<T>(this T value) where T : IAsyncDisposablepublic static ValueTask DisposeAllAsync(this IEnumerable<object?> collection)public static ValueTask DisposeAllIgnoringExceptionsAsync(this IEnumerable<object?> collection)DisposeAllAsync() and DisposeAllIgnoringExceptionsAsync() prefer DisposeAsync; AsAsyncSharedReference() calls AsyncSharedReference.Create./guides/dispose-many-resources/
SemaphoreSlimExtensionspublic static class SemaphoreSlimExtensionspublic static ValueDisposable<SemaphoreSlim> Lock(this SemaphoreSlim semaphore, CancellationToken cancellationToken = default)public static ValueTask<ValueDisposable<SemaphoreSlim>> LockAsync(this SemaphoreSlim semaphore, CancellationToken cancellationToken = default)Lock() and LockAsync() wait for the semaphore and return a scope that releases it; a cancelled wait throws OperationCanceledException./guides/scope-a-lock/
ReaderWriterLockSlimExtensionspublic static class ReaderWriterLockSlimExtensionspublic static ValueDisposable<ReaderWriterLockSlim> ReadLock(this ReaderWriterLockSlim readerWriterLock)public static ValueDisposable<ReaderWriterLockSlim> UpgradeableReadLock(this ReaderWriterLockSlim readerWriterLock)public static ValueDisposable<ReaderWriterLockSlim> WriteLock(this ReaderWriterLockSlim readerWriterLock)ReadLock(), UpgradeableReadLock() and WriteLock() enter the lock and return a scope that exits it./guides/scope-a-lock/

DisposableExtensions, AsyncDisposableExtensions, SemaphoreSlimExtensions and ReaderWriterLockSlimExtensions are C# 14 extension blocks compiled to ordinary static extension methods, so a project on an earlier C# version calls them the same way, or in their static form, DisposableExtensions.DisposeAll(items).

Terminal window
dotnet add package NCode.Disposables

This is one package, with no dependencies, and nuget.org lists its target framework on its Frameworks tab.