Incendium.Result
1.0.4
dotnet add package Incendium.Result --version 1.0.4
NuGet\Install-Package Incendium.Result -Version 1.0.4
<PackageReference Include="Incendium.Result" Version="1.0.4" />
paket add Incendium.Result --version 1.0.4
#r "nuget: Incendium.Result, 1.0.4"
// Install Incendium.Result as a Cake Addin #addin nuget:?package=Incendium.Result&version=1.0.4 // Install Incendium.Result as a Cake Tool #tool nuget:?package=Incendium.Result&version=1.0.4
Incendium.Result
Incendium.Result is a small .NET Standard 2.1 library, which provides Error
, Result<T>
and NullableResult<T>
useful types.
These types allow you to return success value or error from asynchronous and synchronous methods without explicit indication of the result type when returning and with convenient type deconstruction during processing the result.
These type also can be used for less error handling through exception mechanisms where possible.
Getting started
Installation
PM> Install-Package Incendium.Result
Result<T>
If you need to return either a not-null value or an error from a method, you can use the Result<T>
type:
public async Result<string> GetStringAsync() {
// ...
if (condition1) {
return "Test string result";
} else {
return new Error(code: 123, message: "Test error");
}
try {
// ...
} catch (Exception e) {
return new Error(code: 321, message: "Test error", exception: e);
}
}
Then processing the result might look like this:
var (str, error) = await GetStringAsync();
if (error != null) {
log.LogError(
error.Exception(),
"Error with code {@code} and message {@message}",
error.Code,
error.Message);
}
The Result<T>
instance can be created only from non-null value or from non-null error:
public Result<Foo> GetFooAsync() {
return new Foo(); // correct
// return new Error(); // correct
// return (Foo)null; // incorrect, CS8600 and CS8625 warnings, throws ArgumentNullException
// return (Foo)null!; // incorrect, throws ArgumentNullException
// return (Foo?)null; // incorrect, CS8625 warning, throws ArgumentNullException
// return (Foo?)null!; // incorrect, throws ArgumentNullException
// return (Error)null; // incorrect, CS8600 and CS8625 warnings, throws ArgumentNullException
// return (Error)null!; // incorrect, throws ArgumentNullException
// return (Error?)null; // incorrect, CS8625 warning, throws ArgumentNullException
// return (Error?)null!; // incorrect, throws ArgumentNullException
}
NullableResult<T>
If the successful return value can be null, you must use the NullableResult<T>
type:
public NullableResult<Foo> GetFooAsync() {
return new Foo(); // correct
// return new Error(); // correct
// return (Foo?)null; // correct
// return (Foo)null; // correct with CS8600 warning
// return (Foo)null!; // correct
// return (Error)null; // incorrect, CS8600 and CS8625 warnings, throws ArgumentNullException
// return (Error)null!; // incorrect, throws ArgumentNullException
// return (Error?)null; // incorrect, CS8625 warning, throws ArgumentNullException
// return (Error?)null!; // incorrect, throws ArgumentNullException
}
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. 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 was computed. 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 was computed. 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. |
.NET Core | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.1 is compatible. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.1
- Microsoft.Extensions.Logging.Abstractions (>= 8.0.1)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Incendium.Result:
Package | Downloads |
---|---|
Revelium.Evm
Revelium.Evm is .NET integration library for Etherlink and EVM-compatible networks |
GitHub repositories
This package is not used by any popular GitHub repositories.