TryDisposable 8.0.1

dotnet add package TryDisposable --version 8.0.1                
NuGet\Install-Package TryDisposable -Version 8.0.1                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="TryDisposable" Version="8.0.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add TryDisposable --version 8.0.1                
#r "nuget: TryDisposable, 8.0.1"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install TryDisposable as a Cake Addin
#addin nuget:?package=TryDisposable&version=8.0.1

// Install TryDisposable as a Cake Tool
#tool nuget:?package=TryDisposable&version=8.0.1                

Nuget Nuget

TryDisposable

Wrap an object in a disposable decorator to attempt to dispose the object later. This is useful when retrieving an instance of an object from a factory or container while only having an interface reference. If the interface does not implement IDisposable, but the concrete class does, this will allow the instance to be disposed.

##Example 1

Use the simple TryDispose() method available on any object.

object obj = new object();
obj.TryDispose();

##Example 2

Wrap an object in a using statement. Use the instance property to access the object.

ITemporaryFolder tempFolder = TemporaryFolder.Factory.Create();

using (ITryDisposable<ITemporaryFolder> disposableTempFolder = TryDisposableFactory.Create(tempFolder))
{
	string path = disposableTempFolder.Instance.Path;

	// If tempFolder is disposable, it will get disposed, otherwise it will be ignored.
}

##Example 2

Use the following if the underlying object does not need to be accessed through the ITryDisposbale<TUnderlyingItem> interface.

using (ITryDisposable disposableTempFolder = TryDisposableFactory.Create(tempFolder))
{
	// If tempFolder is disposable, it will get disposed, otherwise it will be ignored.
}
Product Compatible and additional computed target framework versions.
.NET 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net8.0

    • No dependencies.

NuGet packages (12)

Showing the top 5 NuGet packages that depend on TryDisposable:

Package Downloads
Diamond.Core.Workflow.State

This library provides an implementation of the state dictionary and provides several default type converters.

Diamond.Core.Workflow

This library provides workflow interfaces and abstract or default implementations for common patterns.

Diamond.Core.AspNetCore.DoAction

Provides the Do pattern execution for ASP.NET Core MVC core projects.

Diamond.Patterns.WorkFlow

This library provides work-flow interfaces and abstract or default implementations for common patterns.

Diamond.Core.Decorator

This library provides a basic implementation of the decorator factory.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
8.0.1 208 9/11/2024
8.0.0 618 11/25/2023
1.5.1 12,019 1/16/2022
1.4.0 10,655 12/3/2020
1.3.1 3,681 4/14/2020
1.3.0 2,737 1/25/2020
1.2.0 513 1/12/2020
1.1.0 521 1/12/2020
1.0.0 4,989 5/28/2019