Result.Core 1.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package Result.Core --version 1.0.0
                    
NuGet\Install-Package Result.Core -Version 1.0.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="Result.Core" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Result.Core" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Result.Core" />
                    
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 Result.Core --version 1.0.0
                    
#r "nuget: Result.Core, 1.0.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 Result.Core@1.0.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=Result.Core&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Result.Core&version=1.0.0
                    
Install as a Cake Tool

Result.Core

A lightweight, dependency-free functional Result<T, E> library for modern .NET. It is inspired by Rust's Result while staying idiomatic to C# with structured failure metadata and reusable templates.

Why use it?

  • Replace exceptions in normal control flow with explicit successes and failures.
  • Keep domain logic clear in application services, APIs, authentication flows, and data access layers.
  • Share consistent error templates across bounded contexts.

Features

  • Result<T, E> success/failure wrapper with implicit conversions.
  • Structured failures: Failure, FailureCode, FailureTemplate, and CommonFailureTypes.
  • Helpers for Match, Map, Bind, Unwrap, and TryUnwrap.
  • Zero runtime dependencies with XML docs, SourceLink, and full unit test coverage.

Installation

Use the package name Result.Core:

 dotnet add package Result.Core

Or via PackageReference:

<ItemGroup>
  <PackageReference Include="Result.Core" Version="1.0.0" />
</ItemGroup>

Quick start

using Result.Core;

Result<int, Failure> Divide(int a, int b)
{
    if (b == 0)
        return CommonFailureTypes.ValidationError.CreateWithMessage("Division by zero.");

    return a / b; // implicit conversion to Result<int, Failure>
}

var result = Divide(10, 2);

int value = result.Match(
    onSuccess: v => v,
    onFailure: e => throw new InvalidOperationException(e.Message));

Transform results

using Result.Core;

var userResult = Result<int, Failure>.Success(1)
    .Bind(id => id == 1
        ? "Ruffallow"
        : CommonFailureTypes.NoDataFound.CreateWithArgs(id))
    .Map(name => name.ToUpperInvariant());

if (userResult.TryUnwrap(out var user, out _))
    Console.WriteLine(user);

Failure model

  • FailureCode: numeric ID + string code (e.g. 300, "COMMON.NO_DATA_FOUND").
  • FailureTemplate: reusable definition with a message template.
  • Failure: concrete error instance used as E in Result<T, E>.
  • CommonFailureTypes: shared templates for validation, auth, data, network, and business errors.

Creating failures:

var failure = CommonFailureTypes.NotAuthorized.Create();
Console.WriteLine(failure.Code.Code);   // COMMON.NOT_AUTHORIZED
Console.WriteLine(failure.Message);     // You are not authorized to perform this action.

Categories in CommonFailureTypes

  • 1–99 General: Unknown, InternalError, OperationFailed
  • 100–199 Validation: ValidationError, InvalidFormat, ValueOutOfRange, RequiredFieldMissing, InvalidEnumValue
  • 200–299 Authentication/Authorization: NotAuthorized, NotAuthenticated, Forbidden, TokenExpired, InvalidCredentials
  • 300–399 Data/Storage: NoDataFound, ParameterNotFound, ConcurrencyConflict, AlreadyExists, NotUnique, DataCorrupted
  • 400–499 External/Network: ExternalServiceUnavailable, ExternalCallFailed, Timeout, NetworkError
  • 500–599 Business: ActionAlreadyPerformed, PreconditionsNotMet, InvalidState, ResourceLocked

Project structure

Result.Core/
  src/Result.Core/           # Library project
  tests/Result.Core.Tests/   # xUnit test project
  LICENSE
  README.md
  Result.Core.sln

Contributing

Issues and pull requests are welcome.

Support

If you find this library useful, please star the repository — it helps others discover the project and motivates further improvements.

Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  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.
  • net9.0

    • No dependencies.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.4 1 1/7/2026
1.0.3 1 1/7/2026
1.0.2 0 1/7/2026
1.0.0 0 12/8/2025