TryDisposable 1.5.1

.NET 5.0 .NET Core 3.1 .NET Standard 1.3 .NET Framework 4.5
Install-Package TryDisposable -Version 1.5.1
dotnet add package TryDisposable --version 1.5.1
<PackageReference Include="TryDisposable" Version="1.5.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add TryDisposable --version 1.5.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: TryDisposable, 1.5.1"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. 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=1.5.1

// Install TryDisposable as a Cake Tool
#tool nuget:?package=TryDisposable&version=1.5.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

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 Versions
.NET net5.0 net5.0-windows net6.0 net6.0-android net6.0-ios net6.0-maccatalyst net6.0-macos net6.0-tvos net6.0-windows
.NET Core netcoreapp1.0 netcoreapp1.1 netcoreapp2.0 netcoreapp2.1 netcoreapp2.2 netcoreapp3.0 netcoreapp3.1
.NET Standard netstandard1.3 netstandard1.4 netstandard1.5 netstandard1.6 netstandard2.0 netstandard2.1
.NET Framework net45 net451 net452 net46 net461 net462 net463 net47 net471 net472 net48
MonoAndroid monoandroid
MonoMac monomac
MonoTouch monotouch
Tizen tizen30 tizen40 tizen60
Universal Windows Platform uap uap10.0
Xamarin.iOS xamarinios
Xamarin.Mac xamarinmac
Xamarin.TVOS xamarintvos
Xamarin.WatchOS xamarinwatchos
Compatible target framework(s)
Additional computed target framework(s)
Learn more about Target Frameworks and .NET Standard.
  • .NETCoreApp 3.1

    • No dependencies.
  • .NETFramework 4.5

    • No dependencies.
  • .NETFramework 4.6.1

    • No dependencies.
  • .NETStandard 1.3

  • .NETStandard 2.0

    • No dependencies.
  • .NETStandard 2.1

    • No dependencies.
  • net5.0

    • No dependencies.
  • net6.0

    • No dependencies.

NuGet packages (12)

Showing the top 5 NuGet packages that depend on TryDisposable:

Package Downloads
Diamond.Patterns.WorkFlow

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

Diamond.Patterns.Decorator

This library provides a basic implementation of the decorator factory.

Diamond.Core.Workflow.State

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

Diamond.Core.Decorator

This library provides a basic implementation of the decorator factory.

Diamond.Core.AspNetCore.DoAction

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

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.5.1 510 1/16/2022
1.4.0 2,015 12/3/2020
1.3.1 891 4/14/2020
1.3.0 962 1/25/2020
1.2.0 328 1/12/2020
1.1.0 320 1/12/2020
1.0.0 1,482 5/28/2019