Skip to content

Search EricksonLopez.* Ecosystem

Type a library name, NuGet package ID, .NET type, or architectural concept to search across the portal.

Getting Started with EricksonLopez.Result

L0StableNuGet: v3.0.0Local HEAD: v3.2.0AOT: Partial

Install EricksonLopez.Result (3.0.0 on NuGet) to model success and failure explicitly without throwing exceptions for expected business rejections.

dotnet add package EricksonLopez.Result --version 3.0.0

For HTTP APIs and unit tests, add the companion packages as needed:

Terminal window
dotnet add package EricksonLopez.Result.AspNetCore --version 3.0.0
dotnet add package EricksonLopez.Result.Testing --version 3.0.0

Define static or factory Error descriptors and chain Ensure, Map, and Match:

using System;
using EricksonLopez.Result;
namespace Example.ResultQuickStart;
public static class OrderErrors
{
public static Error NotFound(Guid orderId) =>
Error.NotFound("Order.NotFound", $"Order '{orderId}' was not found.");
public static readonly Error InvalidQuantity =
Error.Validation("Order.InvalidQuantity", "Quantity must be at least 1.");
}
public sealed record OrderDraft(Guid OrderId, int Quantity, decimal UnitPrice);
public static class OrderPricing
{
public static Result<decimal> CalculateTotal(OrderDraft draft) =>
Result.Success(draft)
.Ensure(static d => d.Quantity > 0, OrderErrors.InvalidQuantity)
.Ensure(
static d => d.UnitPrice > 0m,
Error.Validation("Order.InvalidPrice", "Unit price must exceed zero."))
.Map(static d => d.Quantity * d.UnitPrice);
public static Result ValidateBatch(int count) =>
count > 0
? Result.Success()
: Result.Failure(OrderErrors.InvalidQuantity);
}