Incendium.Result 1.0.4

dotnet add package Incendium.Result --version 1.0.4                
NuGet\Install-Package Incendium.Result -Version 1.0.4                
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="Incendium.Result" Version="1.0.4" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Incendium.Result --version 1.0.4                
#r "nuget: Incendium.Result, 1.0.4"                
#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 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

License: MIT NuGet Version NuGet Downloads

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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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.

Version Downloads Last updated
1.0.4 91 8/29/2024
1.0.3 84 8/29/2024
1.0.2 118 8/15/2024
1.0.1 111 8/12/2024
1.0.0 102 8/12/2024