CSharpEssentials.Results 3.0.5

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

CSharpEssentials.Results

Functional Result pattern for explicit success/failure handling in .NET. No exceptions for control flow.

Features

  • Result & Result<T> — Value-type results with implicit conversions from values and errors.
  • Railway Oriented Programming — Chain operations with Then, Bind, Map, Ensure.
  • Error Aggregation — Collect multiple validation errors in one result.
  • Async Support — Full async/await across all extension methods.
  • Safe ExecutionTryCatch to wrap exceptions into results.

Installation

dotnet add package CSharpEssentials.Results

Usage

Creating Results

using CSharpEssentials.ResultPattern;
using CSharpEssentials.Errors;

public Result<int> GetUser(int id)
{
    if (id <= 0)
        return Error.Validation("Id.Invalid", "ID must be positive.");

    return 42; // implicit conversion to Result<int>
}

public Result DeleteUser(int id)
{
    if (id <= 0)
        return Error.Validation("Id.Invalid", "ID must be positive.");

    return Result.Success();
}

Returning Failures

Use Result.Failure or Result<TValue>.Failure to explicitly construct a failed result without throwing an exception:

// Non-generic failure
Result fail = Result.Failure(Error.Validation("Input.Invalid", "Input was invalid."));

// Generic failure — no value, just an error
Result<string> fail1 = Result.Failure<string>(Error.NotFound("User.NotFound", "User not found."));
Result<string> fail2 = Result<string>.Failure(Error.Conflict("User.Duplicate", "User already exists."));

// Multiple errors in one failure
Result<int> multiError = Result.Failure<int>(
    Error.Validation("Name.Empty", "Name is required."),
    Error.Validation("Email.Invalid", "Email is invalid."));

// Implicit conversion from Error (shorthand)
Result<string> implicit1 = Error.Unauthorized("Token.Expired", "Token has expired.");

All three styles are equivalent — choose based on readability preference. Result.Failure<T> is the most explicit and self-documenting.

Chaining

Result<int> Parse(string input)
{
    if (int.TryParse(input, out int n))
        return n;
    return Error.Validation("Parse", "Not a number.");
}

Result<int> result = Parse("5")
    .Then(n => n * 2)
    .Then(n => n + 10);

Ensuring

Result<int> ensured = Result.Success(50)
    .Ensure(v => v > 0, Error.Validation("Range", "Must be positive."))
    .Ensure(v => v < 100, Error.Validation("Range", "Must be less than 100."));

Matching

string message = GetUser(10).Match(
    onSuccess: user => $"User: {user}",
    onError: errors => $"Failed: {errors[0].Description}");

Combining Results

var r1 = Result.Success();
var r2 = Result.Success();
var r3 = Result.Failure(Error.NotFound());

Result combined = Result.And(r1, r2, r3); // Failure

Safe Execution

Result<int> result = Result.Try(() => 10 / 0, ex => Error.Exception(ex));

Async

Result<int> result = await FetchUserAsync(id)
    .ThenAsync(user => EnrichAsync(user))
    .EnsureAsync(v => IsValidAsync(v), Error.Validation("Invalid", "Not valid."));
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  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 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 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.  net11.0 is compatible. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (8)

Showing the top 5 NuGet packages that depend on CSharpEssentials.Results:

Package Downloads
CSharpEssentials

A comprehensive C# library enhancing functional programming capabilities with type-safe monads (Maybe, Result), discriminated unions (Any), and robust error handling. Features include: domain-driven design support, enhanced Entity Framework integration, testable time management, JSON utilities, and LINQ extensions. Built for modern C# development with focus on maintainability, testability, and functional programming principles.

CSharpEssentials.EntityFrameworkCore

Enhances Entity Framework Core with functional programming patterns and DDD-friendly features. Includes base entity classes, soft delete support, audit trails, query filters, optimistic concurrency, PostgreSQL integration, query performance monitoring, and domain event handling. Perfect for building maintainable and scalable data access layers in modern .NET applications.

CSharpEssentials.AspNetCore

A comprehensive ASP.NET Core library that enhances functional programming capabilities in web applications. Features include API versioning, global exception handling with enhanced problem details, advanced Swagger/OpenAPI configuration, model validation, optimized JSON handling, and seamless integration with CSharpEssentials core functional patterns (Result, Maybe, Rule Engine). Perfect for building robust, maintainable, and type-safe web APIs following functional programming principles.

CSharpEssentials.Maybe

Maybe monad implementation with LINQ support for functional programming in C#. Provides type-safe null handling, eliminates null reference exceptions, and enables functional composition. Essential for functional programming patterns and safe value handling.

CSharpEssentials.Entity

Domain-driven design (DDD) entity base classes and patterns for CSharpEssentials. Provides EntityBase<TId> with soft delete functionality, audit trails, and domain event integration. Essential for building robust domain models with type safety and functional programming principles.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
3.0.5 321 5/7/2026
3.0.4 317 5/6/2026
3.0.3 313 5/5/2026
3.0.2 288 5/5/2026
3.0.1 278 5/3/2026
3.0.0 276 5/3/2026
2.1.0 384 11/26/2025
2.0.9 298 9/30/2025
2.0.8 310 9/29/2025
2.0.7 287 9/29/2025
2.0.6 292 9/29/2025
2.0.5 280 9/29/2025
2.0.4 290 9/28/2025
2.0.3 295 9/28/2025
2.0.2 296 9/28/2025
2.0.1 286 9/28/2025
2.0.0 296 9/28/2025