Defer 1.2.0
.NET 5.0
This package targets .NET 5.0. The package is compatible with this framework or higher.
.NET Core 1.0
This package targets .NET Core 1.0. The package is compatible with this framework or higher.
.NET Standard 1.0
This package targets .NET Standard 1.0. The package is compatible with this framework or higher.
.NET Framework 3.5
This package targets .NET Framework 3.5. The package is compatible with this framework or higher.
dotnet add package Defer --version 1.2.0
NuGet\Install-Package Defer -Version 1.2.0
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="Defer" Version="1.2.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Defer --version 1.2.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Defer, 1.2.0"
#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 Defer as a Cake Addin #addin nuget:?package=Defer&version=1.2.0 // Install Defer as a Cake Tool #tool nuget:?package=Defer&version=1.2.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Defer
This repository provides IDeferable
to emulate Golang's defer
keyword in C#.
Installing
The package is available on NuGet. To install, run:
dotnet add package Defer
Build Status
Using Deferable
Usage of Deferable
// Deferable.Defer
Console.WriteLine("Hello, World!");
using (Deferable.Defer(() => Console.WriteLine("Goodbye, World!")))
{
Console.WriteLine("Do something");
}
// output:
// Hello, World!
// Do something
// Goodbye, World!
Usage of Deferable<T>
// Deferable<T>
int status = -1;
Console.WriteLine("init status: " + status);
using (Deferable<int>.Defer(value => status = value, initValue: 1, deferValue: 0))
{
Console.WriteLine("doing something status: " + status);
}
Console.WriteLine("after defer status: " + status);
// output:
// init status: -1
// doing something status: 1
// after defer status: 0
Usage of BooleanDeferable
// BooleanDeferable
bool flag = default;
Console.WriteLine("init flag: " + flag);
using (BooleanDeferable.Defer(value => flag = value))
{
Console.WriteLine("doing something flag: " + flag);
}
Console.WriteLine("after defer flag: " + flag);
// output:
// init flag: False
// doing something flag: True
// after defer flag: False
Usage of RefDeferable<T>
// RefDeferable<T>
// Only applicable for .NET Standard 2.1, .NET Core 3.0, or later versions
double value = -1d;
Console.WriteLine("init value: " + value);
using (RefDeferable<double>.Defer(ref value, 0d, 1d))
{
Console.WriteLine("doing something value: " + value);
}
Console.WriteLine("after defer value: " + value);
// output:
// init value: -1
// doing something value: 0
// after defer value: 1
References
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 is compatible. 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. |
.NET Core | netcoreapp1.0 is compatible. netcoreapp1.1 is compatible. netcoreapp2.0 is compatible. netcoreapp2.1 is compatible. netcoreapp2.2 is compatible. netcoreapp3.0 is compatible. netcoreapp3.1 is compatible. |
.NET Standard | netstandard1.0 is compatible. netstandard1.1 is compatible. netstandard1.2 is compatible. netstandard1.3 is compatible. netstandard1.4 is compatible. netstandard1.5 is compatible. netstandard1.6 is compatible. netstandard2.0 is compatible. netstandard2.1 is compatible. |
.NET Framework | net35 is compatible. net40 is compatible. net403 was computed. net45 is compatible. net451 is compatible. net452 is compatible. net46 is compatible. net461 is compatible. net462 is compatible. net463 was computed. net47 is compatible. net471 is compatible. net472 is compatible. net48 is compatible. net481 is compatible. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen30 was computed. tizen40 was computed. tizen60 was computed. |
Universal Windows Platform | uap was computed. uap10.0 was computed. |
Windows Phone | wp8 was computed. wp81 was computed. wpa81 was computed. |
Windows Store | netcore was computed. netcore45 was computed. netcore451 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
.NETCoreApp 1.0
- Microsoft.NETCore.App (>= 1.0.5)
-
.NETCoreApp 1.1
- Microsoft.NETCore.App (>= 1.1.2)
-
.NETCoreApp 2.0
- No dependencies.
-
.NETCoreApp 2.1
- No dependencies.
-
.NETCoreApp 2.2
- No dependencies.
-
.NETCoreApp 3.0
- No dependencies.
-
.NETCoreApp 3.1
- No dependencies.
-
.NETFramework 3.5
- No dependencies.
-
.NETFramework 4.0
- No dependencies.
-
.NETFramework 4.5
- No dependencies.
-
.NETFramework 4.5.1
- No dependencies.
-
.NETFramework 4.5.2
- No dependencies.
-
.NETFramework 4.6
- No dependencies.
-
.NETFramework 4.6.1
- No dependencies.
-
.NETFramework 4.6.2
- No dependencies.
-
.NETFramework 4.7
- No dependencies.
-
.NETFramework 4.7.1
- No dependencies.
-
.NETFramework 4.7.2
- No dependencies.
-
.NETFramework 4.8
- No dependencies.
-
.NETFramework 4.8.1
- No dependencies.
-
.NETStandard 1.0
- NETStandard.Library (>= 1.6.1)
-
.NETStandard 1.1
- NETStandard.Library (>= 1.6.1)
-
.NETStandard 1.2
- NETStandard.Library (>= 1.6.1)
-
.NETStandard 1.3
- NETStandard.Library (>= 1.6.1)
-
.NETStandard 1.4
- NETStandard.Library (>= 1.6.1)
-
.NETStandard 1.5
- NETStandard.Library (>= 1.6.1)
-
.NETStandard 1.6
- NETStandard.Library (>= 1.6.1)
-
.NETStandard 2.0
- No dependencies.
-
.NETStandard 2.1
- No dependencies.
-
net5.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.