TedToolkit.Annotations.Ownership
2026.7.16.3
dotnet add package TedToolkit.Annotations.Ownership --version 2026.7.16.3
NuGet\Install-Package TedToolkit.Annotations.Ownership -Version 2026.7.16.3
<PackageReference Include="TedToolkit.Annotations.Ownership" Version="2026.7.16.3" />
<PackageVersion Include="TedToolkit.Annotations.Ownership" Version="2026.7.16.3" />
<PackageReference Include="TedToolkit.Annotations.Ownership" />
paket add TedToolkit.Annotations.Ownership --version 2026.7.16.3
#r "nuget: TedToolkit.Annotations.Ownership, 2026.7.16.3"
#:package TedToolkit.Annotations.Ownership@2026.7.16.3
#addin nuget:?package=TedToolkit.Annotations.Ownership&version=2026.7.16.3
#tool nuget:?package=TedToolkit.Annotations.Ownership&version=2026.7.16.3
TedToolkit.Annotations.Ownership
Document ownership transfer and callback lifetime for disposable resources. The bundled analyzer follows these contracts to detect lifetime mistakes.
Install
dotnet add package TedToolkit.Annotations.Ownership
No separate analyzer package or configuration is required.
Use
Annotate the boundary where ownership changes. Returns and out parameters transfer ownership by default; ordinary parameters borrow by default. State a non-default contract explicitly:
using TedToolkit.Annotations.Ownership;
public sealed class Cache
{
public void Store([Ownership(OwnershipKind.TRANSFERRED)] IDisposable item)
{
// This instance now owns and must dispose item.
}
[return: Ownership(OwnershipKind.UNCHANGED)]
public Stream GetSharedStream() => _stream;
}
For ref parameters and properties, specify the direction with OwnershipFlow.INPUT or OwnershipFlow.OUTPUT when their input and output contracts differ.
Annotate callback parameters to show whether they can escape the call:
public void Subscribe(
[CallbackLifetime(CallbackLifetimeKind.SUBSCRIPTION)] Action handler)
{
_handlers += handler;
}
public void Visit([CallbackLifetime(CallbackLifetimeKind.IMMEDIATE)] Action visitor)
=> visitor();
Use DEFERRED for a callback retained for later invocation, and SUBSCRIPTION for a callback retained until unsubscription or disposal.
Attribute reference
| Attribute | Effect | Use it when |
|---|---|---|
Ownership |
States whether a disposable value is borrowed (UNCHANGED) or ownership is transferred (TRANSFERRED) across a parameter, return, property, or field boundary. |
The analyzer default for the boundary does not describe the API, especially when a callee takes responsibility for a parameter or returns a shared resource. |
CallbackLifetime |
States whether a callback is invoked only during the call (IMMEDIATE), kept for a later call (DEFERRED), or retained as a subscription (SUBSCRIPTION). |
A callback can outlive the invoking call, or callers need to know it definitely cannot escape. |
Ownership is not a disposal operation; it documents who is responsible for disposal after the boundary. Use OwnershipFlow.INPUT and OUTPUT only for ref parameters and properties with distinct incoming and outgoing contracts.
Analyzer diagnostics
The analyzer checks both IDisposable and IAsyncDisposable lifetimes. It reports double disposal, use after disposal or transfer, leaks, borrowed disposal, callback capture that outlives a resource, unobserved asynchronous disposal, and invalid ownership contracts (TAO001 through TAO014).
Compatibility
Targets .NET 6.0 through .NET 10.0, .NET Framework 4.7.2 and 4.8, and .NET Standard 2.0 and 2.1.
Related documentation
License
Licensed under the GNU Lesser General Public License v3.0.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 is compatible. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 is compatible. |
| .NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 is compatible. net48 is compatible. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETFramework 4.7.2
- No dependencies.
-
.NETFramework 4.8
- No dependencies.
-
.NETStandard 2.0
- No dependencies.
-
.NETStandard 2.1
- No dependencies.
-
net10.0
- No dependencies.
-
net6.0
- No dependencies.
-
net7.0
- No dependencies.
-
net8.0
- No dependencies.
-
net9.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 2026.7.16.3 | 113 | 7/16/2026 |
| 2026.7.16.2 | 97 | 7/16/2026 |
| 2026.7.16.1 | 107 | 7/16/2026 |
| 2026.7.16 | 109 | 7/16/2026 |