Fox.ResultKit 1.0.0

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

Fox.ResultKit

A lightweight, type-safe result handling library for .NET applications that eliminates the need for exception-based error handling in business logic.

📋 Overview

Fox.ResultKit provides a clean and functional approach to handle operation results in .NET applications. Instead of throwing exceptions for expected failures, it uses the Result and Result<T> types to explicitly model success and failure states.

Inspired by F# Result type and Scott Wlaschin's Railway Oriented Programming pattern, this library brings functional composition and type-safe error handling to C#.

✨ Features

  • Type-safe Result Handling - Explicit success/failure modeling with Result and Result<T>
  • Railway Oriented Programming - Functional composition with Map, Bind, Ensure, Tap, Match
  • Exception Safety - Try and TryAsync for wrapping unsafe operations
  • Result Composition - Combine multiple validation results
  • Zero Dependencies - No third-party packages, minimal footprint
  • Nullable Reference Types - Full null-safety support
  • Async-First Design - All functional extensions have async variants
  • Multi-targeting - Supports .NET 8, 9, and 10
  • XML Documentation - Complete IntelliSense experience

🚀 Installation

dotnet add package Fox.ResultKit

📖 Basic Usage

Creating Results

using Fox.ResultKit;

// Non-generic Result
Result success = Result.Success();
Result failure = Result.Failure("Operation failed");

// Generic Result with value
Result<int> successValue = Result<int>.Success(42);
Result<int> failureValue = Result<int>.Failure("Invalid input");

Pattern Matching

var result = Result<int>.Success(10);

// Return value
string output = result.Match(
    onSuccess: value => $"Value: {value}",
    onFailure: error => $"Error: {error}"
);

// Void actions
result.Match(
    onSuccess: () => Console.WriteLine("Success!"),
    onFailure: error => Console.WriteLine($"Error: {error}")
);

Railway Oriented Programming

var result = await GetUserById(userId)
    .ToResult($"User {userId} not found")
    .Ensure(user => user.IsActive, "User is not active")
    .Map(user => new UserDto(user.Id, user.Email))
    .Tap(dto => logger.LogInformation("User: {Email}", dto.Email));

return result.Match<IActionResult>(
    onSuccess: dto => Ok(dto),
    onFailure: error => NotFound(error)
);

Validation with Combine

private Result ValidateEmail(string email) =>
    Result.Success()
        .Ensure(() => !string.IsNullOrWhiteSpace(email), "Email required")
        .Ensure(() => email.Contains("@"), "Invalid email");

private Result ValidatePassword(string password) =>
    Result.Success()
        .Ensure(() => password?.Length >= 8, "Min 8 characters");

// Combine validations
var validation = ResultCombineExtensions.Combine(
    ValidateEmail(email),
    ValidatePassword(password)
);

Exception Handling

// Sync
var result = ResultTryExtensions.Try(
    () => int.Parse("123"),
    "Parse failed"
);

// Async
var asyncResult = await ResultTryExtensions.TryAsync(
    async () => await httpClient.GetStringAsync(url),
    "Request failed"
);

🎯 When to Use

✅ Use Fox.ResultKit when:

  • Modeling expected failures (validation, business rules, not found)
  • Building clean domain logic without try-catch noise
  • Explicit error handling in method signatures
  • Composing operations functionally
  • Eliminating null checks

❌ Don't use for:

  • Truly exceptional situations (OOM, hardware failures)
  • Performance-critical hot paths
  • External APIs needing typed error codes

📚 Documentation

For complete documentation and advanced examples, visit the GitHub repository.

📄 License

MIT License - see LICENSE for details.

🙏 Acknowledgments

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

    • No dependencies.
  • net8.0

    • No dependencies.
  • net9.0

    • No dependencies.

NuGet packages (4)

Showing the top 4 NuGet packages that depend on Fox.ResultKit:

Package Downloads
Fox.ConfigKit.ResultKit

ResultKit integration for Fox.ConfigKit - Railway Oriented Programming for configuration validation. Extends Fox.ConfigKit with Result<T> pattern for functional error handling.

Fox.ResultKit.MediatR

MediatR pipeline behavior for automatic Result handling in CQRS commands and queries. Seamlessly integrates Fox.ResultKit with MediatR for clean error handling in request pipelines.

Fox.ChainKit.ResultKit

Result pattern integration for Fox.ChainKit. Enables seamless use of Fox.ResultKit with chain handlers, providing automatic conversion between Result and HandlerResult types with full diagnostics support.

Fox.ValidationKit.ResultKit

Optional Fox.ResultKit integration for Fox.ValidationKit. Provides ValidationResult to Result conversion with fluent API.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.3.0 296 3/1/2026
1.2.0 428 2/10/2026
1.1.0 219 2/9/2026
1.0.0 144 2/8/2026

Initial release with core Result and Result<T> types, functional extensions (Map, Bind, Ensure, Tap, Match), and exception handling utilities.