Kodster.Results 0.1.0

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

Kodster.Results

A result type for expected failures, so they travel as return values instead of exceptions.

No dependencies. Safe to reference from a domain or core project without dragging in a DI container, a validation library, or a web framework.

dotnet add package Kodster.Results

Targets .NET 10.

Result and Result<T>

Result represents an operation that either succeeded or failed with an Error. Result<T> adds a value on the success side.

Result<User> Find(Guid id)
{
    var user = _users.SingleOrDefault(u => u.Id == id);

    return user is null
        ? Error.NotFound("User.NotFound", "User was not found.")
        : user;
}

Neither branch needs a wrapper call. Error converts implicitly to Result and Result<T>, and any TValue converts implicitly to a successful Result<TValue>.

Reading one back:

var result = Find(id);

if (result.IsFailure)
{
    Console.WriteLine(result.Error.Description);
    return;
}

Use(result.Value);

Or branch in a single expression with Match:

var message = result.Match(
    onSuccess: user => $"Found {user.Nickname}",
    onFailure: error => $"Failed: {error.Code}");

Errors

An Error is a record of a code, a human-readable description, and an ErrorType that says what kind of failure it is.

Error.Conflict("OAuth.AlreadyLinked", "That provider is already linked to this account.")
ErrorType Meaning
Validation Input failed a rule
Unauthorized No valid credentials
PaymentRequired Credentials are valid, but the plan or quota does not cover this
Forbidden Authenticated, but not permitted
NotFound No such resource
Conflict Conflicts with current state
Gone Existed once, permanently removed
PreconditionFailed A supplied precondition did not hold
Failure Anything unexpected

Each has a matching factory taking a code and description. The set covers outcomes application code decides; it deliberately excludes failures that belong to the transport layer.

ErrorType is serialised by ordinal value, so new members are only ever appended. Inserting one would change the number every later type serialises as.

Error.None is the sentinel carried by successful results. Constructing a success with an error, or a failure without one, throws.

Validation results

ValidationResult and ValidationResult<T> are failures that carry many errors rather than one — the natural shape for input validation, where you want every broken rule at once.

Error[] errors = [
    Error.Validation("Nickname", "Nickname is required."),
    Error.Validation("Age", "Age must be 13 or older.")
];

return ValidationResult<UserResponse>.WithErrors(errors);

Both implement IValidationResult, so a caller can pattern-match to decide whether to report one error or all of them:

Error[] toReport = result switch
{
    IValidationResult validation => validation.Errors,
    _ => [result.Error]
};

They are otherwise ordinary failed results, with Error set to a general Validation.Error.

Companion packages

  • Kodster.CQRS — request/handler abstraction returning these result types, with validation and logging decorators.
  • Kodster.Results.AspNetCore — maps a failed Result onto an HTTP ProblemDetails response.

License

MIT

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 Kodster.Results:

Package Downloads
Kodster.Results.AspNetCore

Maps Kodster.Results failures onto ASP.NET Core ProblemDetails responses.

Kodster.CQRS

Minimal request/handler abstraction with validation and logging decorators.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.1.0 135 8/19/2026