StrongResult 1.0.1
dotnet add package StrongResult --version 1.0.1
NuGet\Install-Package StrongResult -Version 1.0.1
<PackageReference Include="StrongResult" Version="1.0.1" />
<PackageVersion Include="StrongResult" Version="1.0.1" />
<PackageReference Include="StrongResult" />
paket add StrongResult --version 1.0.1
#r "nuget: StrongResult, 1.0.1"
#:package StrongResult@1.0.1
#addin nuget:?package=StrongResult&version=1.0.1
#tool nuget:?package=StrongResult&version=1.0.1
StrongResult
StrongResult is a C# library for representing operation results with explicit success, failure, error, and warning states. It provides both generic (Result<T>) and non-generic (Result) result types for clear, type-safe, and expressive error handling.
Features
- Result Types: Use
Resultfor operations without a return value, andResult<T>for operations that return a value. - Success & Failure: Distinguish between hard success, partial success (with warnings), controlled errors, and hard failures.
- Warnings & Errors: Attach warnings and errors to results for detailed diagnostics.
- Immutability: All result types are immutable and thread-safe.
- Fluent API: Easily create, map, bind, and match results.
Quick Start
Installation
Add StrongResult to your project via NuGet:
dotnet add package StrongResult
Usage
Non-Generic Result
using StrongResult.NonGeneric;
// Hard success
var result = Result.Ok();
// Partial success with warnings
var warning = Warning.Create("W1", "Minor issue");
var partial = Result.PartialSuccess(warning);
// Controlled error
var error = Error.Create("E1", "Validation failed");
var controlled = Result.ControlledError(error, warning);
// Hard failure
var failure = Result.Fail(error);
Generic Result
using StrongResult.Generic;
// Hard success with value
var result = Result<string>.Ok("value");
// Partial success with value and warnings
var partial = Result<string>.PartialSuccess("value", warning);
// Controlled error with value type
var controlled = Result<string>.ControlledError(error, warning);
// Hard failure
var failure = Result<string>.Fail(error);
Handling Results
if (result.IsSuccess)
{
// Access result.Value for generic results
}
else
{
// Handle result.Error and result.Warnings
}
Implicit Conversion
string value = Result<string>.Ok("abc"); // Implicit conversion
Mapping and Binding
var mapped = result.Map(s => s.Length);
var bound = result.Bind(s => Result<int>.Ok(s.Length));
Fluent Result Actions
OnSuccess
result.OnSuccess(() => Console.WriteLine("Success!"));
OnFailure
result.OnFailure(error => Console.WriteLine($"Failed: {error.Message}"));
OnWarnings
result.OnWarnings(warnings =>
{
foreach (var w in warnings)
Console.WriteLine($"Warning: {w.Message}");
});
ForEachWarning
result.ForEachWarning(warning => Console.WriteLine($"Warning: {warning.Code} - {warning.Message}"));
Result Kinds
HardSuccess: Operation completed successfully.PartialSuccess: Operation succeeded with warnings.ControlledError: Operation failed with expected/controlled error.HardFailure: Operation failed with unrecoverable error.
API Reference
ResultandResult<T>: Main result types.ErrorandWarning: Attach error and warning information.- Extension methods:
Map,Bind,Match,OnSuccess,OnFailure,OnWarnings,ForEachWarningetc.
Testing
Unit tests are provided for all core scenarios. See the StrongResult.Test project for examples.
Contributing
Contributions and feedback are welcome! Please open issues or submit pull requests on GitHub.
.NET 8 / C# 12 compatible
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. 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. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. 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. |
-
net8.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.