StrongResult 1.0.1

dotnet add package StrongResult --version 1.0.1
                    
NuGet\Install-Package StrongResult -Version 1.0.1
                    
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="StrongResult" Version="1.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="StrongResult" Version="1.0.1" />
                    
Directory.Packages.props
<PackageReference Include="StrongResult" />
                    
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 StrongResult --version 1.0.1
                    
#r "nuget: StrongResult, 1.0.1"
                    
#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 StrongResult@1.0.1
                    
#: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=StrongResult&version=1.0.1
                    
Install as a Cake Addin
#tool nuget:?package=StrongResult&version=1.0.1
                    
Install as a Cake Tool

Build NuGet Version

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 Result for operations without a return value, and Result<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

  • Result and Result<T>: Main result types.
  • Error and Warning: Attach error and warning information.
  • Extension methods: Map, Bind, Match, OnSuccess, OnFailure,OnWarnings, ForEachWarning etc.

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

Version Downloads Last Updated
1.0.1 164 10/4/2025
1.0.0 159 10/4/2025
0.1.1 162 10/4/2025