KrzysKlein.ResultDotNet 0.3.0

dotnet add package KrzysKlein.ResultDotNet --version 0.3.0
                    
NuGet\Install-Package KrzysKlein.ResultDotNet -Version 0.3.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="KrzysKlein.ResultDotNet" Version="0.3.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="KrzysKlein.ResultDotNet" Version="0.3.0" />
                    
Directory.Packages.props
<PackageReference Include="KrzysKlein.ResultDotNet" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add KrzysKlein.ResultDotNet --version 0.3.0
                    
#r "nuget: KrzysKlein.ResultDotNet, 0.3.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.
#:package KrzysKlein.ResultDotNet@0.3.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=KrzysKlein.ResultDotNet&version=0.3.0
                    
Install as a Cake Addin
#tool nuget:?package=KrzysKlein.ResultDotNet&version=0.3.0
                    
Install as a Cake Tool

ResultDotNet

Implementation of the Result Pattern for .NET 10

Overview

ResultDotNet provides a functional approach to error handling and composition in .NET applications. It enables chaining operations, propagating errors, and handling results in a concise and expressive manner.

Installation

Add the package via NuGet:

# .NET CLI
 dotnet add package KrzysKlein.ResultDotNet

Basic Usage

Creating Results

var success = Result.Success();
var successOrError = Result<string>.Success();
var error = Result<string>.FromError("Something went wrong");

var valueResult = Result<int, string>.FromValue(42);
var errorResult = Result<int, string>.FromError("Invalid value");

Chaining Operations

var result = Result<string>.Success()
    .Bind(() => Result<string>.FromError("Next step failed"))
    .Map(() => "Transformed value");

Handling Results

var output = result.Match(
    onSuccess: () => "Operation succeeded",
    onError: error => $"Failed: {error}"
);

ValueResult

Use ValueResult when you want to return a value along with the success or error state in a value type (struct).

var success = ValueResult.Success();
var successOrError = ValueResult<string>.Success();
var error = ValueResult<string>.FromError("Something went wrong");

var valueResult = ValueResult<int, string>.FromValue(42);
var errorResult = ValueResult<int, string>.FromError("Invalid value");

API Overview

  • Bind: Chains operations that return results, propagating errors.
  • Map: Transforms the value in a successful result.
  • Match: Handles both success and error cases.
  • Async variants: BindAsync, MapAsync, MatchAsync for asynchronous workflows.

Examples

See examples for usage in ASP.NET Core APIs.

License

MIT License

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net10.0

    • No dependencies.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on KrzysKlein.ResultDotNet:

Package Downloads
KrzysKlein.ResultDotNet.AspNetCore

Implementation of a Result Pattern - ASP.NET Core Extensions

KrzysKlein.ResultDotNet.FluentValidation

Implementation of a Result Pattern - FluentValidation Extensions

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.3.0 157 3/4/2026
0.2.2 147 2/26/2026
0.2.1 133 2/25/2026
0.2.0 118 2/24/2026
0.1.0 136 2/18/2026