KrzysKlein.ResultDotNet
0.3.0
dotnet add package KrzysKlein.ResultDotNet --version 0.3.0
NuGet\Install-Package KrzysKlein.ResultDotNet -Version 0.3.0
<PackageReference Include="KrzysKlein.ResultDotNet" Version="0.3.0" />
<PackageVersion Include="KrzysKlein.ResultDotNet" Version="0.3.0" />
<PackageReference Include="KrzysKlein.ResultDotNet" />
paket add KrzysKlein.ResultDotNet --version 0.3.0
#r "nuget: KrzysKlein.ResultDotNet, 0.3.0"
#:package KrzysKlein.ResultDotNet@0.3.0
#addin nuget:?package=KrzysKlein.ResultDotNet&version=0.3.0
#tool nuget:?package=KrzysKlein.ResultDotNet&version=0.3.0
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,MatchAsyncfor asynchronous workflows.
Examples
See examples for usage in ASP.NET Core APIs.
License
MIT License
Links
| Product | Versions 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. |
-
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.