CSharpEssentials.Results
3.0.2
See the version list below for details.
dotnet add package CSharpEssentials.Results --version 3.0.2
NuGet\Install-Package CSharpEssentials.Results -Version 3.0.2
<PackageReference Include="CSharpEssentials.Results" Version="3.0.2" />
<PackageVersion Include="CSharpEssentials.Results" Version="3.0.2" />
<PackageReference Include="CSharpEssentials.Results" />
paket add CSharpEssentials.Results --version 3.0.2
#r "nuget: CSharpEssentials.Results, 3.0.2"
#:package CSharpEssentials.Results@3.0.2
#addin nuget:?package=CSharpEssentials.Results&version=3.0.2
#tool nuget:?package=CSharpEssentials.Results&version=3.0.2
CSharpEssentials.Results
CSharpEssentials.Results implements the Result Pattern for functional error handling in .NET. It allows you to represent the success or failure of an operation explicitly, avoiding exceptions for control flow and making your code more robust and readable.
🚀 Features
- Explicit Outcomes:
Result(for void operations) andResult<T>(for value-returning operations). - Immutable: Thread-safe, readonly record structs.
- Multiple Errors: Support for aggregating multiple errors (e.g., for validation).
- Functional Extensions: Rich set of methods like
Map,Bind,Match,Tap,Ensure, andThenfor chaining operations. - Async Support: Full support for async/await in extension methods.
- JSON Support: Built-in attributes for proper serialization.
📦 Installation
dotnet add package CSharpEssentials.Results
🛠 Usage
1. Creating Results
Return Result.Success() or Result.Failure(...).
using CSharpEssentials.ResultPattern;
using CSharpEssentials.Errors;
public Result DoSomething(bool fail)
{
if (fail)
{
return Result.Failure(Error.Failure("Operation.Failed", "Something went wrong."));
}
return Result.Success();
}
public Result<int> GetValue(int id)
{
if (id < 0)
{
// Implicit conversion from Error to Result<T>
return Error.Validation("Id.Invalid", "ID cannot be negative");
}
// Implicit conversion from Value to Result<T>
return 42;
}
2. Functional Chaining (Railway Oriented Programming)
Chain operations so that subsequent steps only run if the previous ones succeeded.
public Result<Order> ProcessOrder(Request request)
{
return ValidateRequest(request)
.Bind(CreateOrder)
.Bind(ProcessPayment)
.Tap(SendEmail) // Side effect (fire and forget, doesn't change result)
.Map(order => order);
}
3. Handling the Result (Match)
At the end of the chain, unwrap the result to handle success and failure cases explicitly.
var result = ProcessOrder(request);
string response = result.Match(
onSuccess: order => $"Order {order.Id} processed!",
onFailure: errors => $"Failed: {errors[0].Description}"
);
4. Combining Results
Combine multiple results; if any fail, the whole operation is a failure.
var r1 = Result.Success();
var r2 = Result.Success();
var r3 = Result.Failure(Error.Unexpected());
var combined = Result.And(r1, r2, r3); // Returns Failure
5. Safe Execution (TryCatch)
Wrap risky code that might throw exceptions into a Result.
var result = Result.TryCatch(() =>
{
// Code that might throw
return File.ReadAllText("config.json");
});
// result is Result<string>, capturing any exception as an Error
| Product | Versions 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. |
-
.NETStandard 2.1
- CSharpEssentials.Errors (>= 3.0.2)
- CSharpEssentials.Json (>= 3.0.2)
- System.Text.Json (>= 9.0.0)
-
net10.0
- CSharpEssentials.Errors (>= 3.0.2)
- CSharpEssentials.Json (>= 3.0.2)
-
net11.0
- CSharpEssentials.Errors (>= 3.0.2)
- CSharpEssentials.Json (>= 3.0.2)
-
net9.0
- CSharpEssentials.Errors (>= 3.0.2)
- CSharpEssentials.Json (>= 3.0.2)
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.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. |
|
|
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. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 3.0.5 | 324 | 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 | 385 | 11/26/2025 |
| 2.0.9 | 299 | 9/30/2025 |
| 2.0.8 | 311 | 9/29/2025 |
| 2.0.7 | 288 | 9/29/2025 |
| 2.0.6 | 293 | 9/29/2025 |
| 2.0.5 | 281 | 9/29/2025 |
| 2.0.4 | 291 | 9/28/2025 |
| 2.0.3 | 297 | 9/28/2025 |
| 2.0.2 | 298 | 9/28/2025 |
| 2.0.1 | 287 | 9/28/2025 |
| 2.0.0 | 297 | 9/28/2025 |