Incendium.Result 1.0.2

There is a newer version of this package available.
See the version list below for details.
dotnet add package Incendium.Result --version 1.0.2                
NuGet\Install-Package Incendium.Result -Version 1.0.2                
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.2" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Incendium.Result --version 1.0.2                
#r "nuget: Incendium.Result, 1.0.2"                
#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.2

// Install Incendium.Result as a Cake Tool
#tool nuget:?package=Incendium.Result&version=1.0.2                

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 warning, throws ArgumentNullException
    return (Foo)null!; // incorrect, throws ArgumentNullException
    return (Foo?)null; // incorrect, CS8604 warning, throws ArgumentNullException
    return (Foo?)null!; // incorrect, 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 async 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, 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 132 8/29/2024
1.0.3 86 8/29/2024
1.0.2 120 8/15/2024
1.0.1 113 8/12/2024
1.0.0 104 8/12/2024