Yaver.Result 2.1.0

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

Yaver.Result

Yaver.Result is a .NET library designed to provide a standardized way to handle operation results, validation, and error management in your applications. It offers a set of result types, extension methods, and utilities to simplify the handling of success, failure, and validation scenarios.

Features

  • Result types for success, error, validation, and common HTTP-like outcomes.
  • Validation support with rich ValidationError details.
  • Paging support with PagedResult<T> and PagedInfo.
  • MessagePack serialization support for result envelopes.
  • Native AOT-friendly resolver strategy and smoke-test coverage.

Result Types

Yaver.Result provides several result types to cover different scenarios:

  • Result: Represents a basic operation result, indicating success or failure, with optional error messages.
  • Result<T>: A generic result type that carries a value of type T on success.
  • PagedResult<T>: Represents a paged result set, including pagination metadata (PagedInfo).
  • ValidationError: Encapsulates validation error details, such as property name, error message, and severity.
  • Result.Void: Used for operations that do not return a value but still indicate success or failure.
  • ResultStatus: Enum representing operation state (Ok, Error, Forbidden, Unauthorized, Invalid, NotFound, Conflict, CriticalError, Unavailable).
  • PagedInfo: Contains pagination information such as page number, page size, and total count.

HTTP Response Code Mapping

Yaver.Result is designed to help map operation results to appropriate HTTP response codes in web APIs:

  • Success (ResultStatus.Ok): Maps to HTTP 200 OK or 201 Created, depending on the operation.
  • Error (ResultStatus.Error): Typically maps to HTTP 400/500 depending on context.
  • Invalid (ResultStatus.Invalid): Maps to HTTP 422 Unprocessable Entity for validation failures.
  • Forbidden (ResultStatus.Forbidden): Maps to HTTP 403 Forbidden.
  • Unauthorized (ResultStatus.Unauthorized): Maps to HTTP 401 Unauthorized.
  • NotFound (ResultStatus.NotFound): Maps to HTTP 404 Not Found.
  • Conflict (ResultStatus.Conflict): Maps to HTTP 409 Conflict.
  • Unavailable (ResultStatus.Unavailable): Maps to HTTP 503 Service Unavailable.

You can use the ResultToResponse utility to convert result objects to HTTP responses in your controllers.

MessagePack and Native AOT

The library includes MessagePack support for result envelopes with an AOT-safe resolver strategy.

  • Use WithYaverResultResolver<T>() to include result envelope formatters for your payload type.
  • Supported envelope types include Result, Result<T>, PagedResult<T>, and ValidationError.
  • Native AOT smoke tests are included in the repository to validate publish and runtime behavior.

Project Structure

  • Result/ — Core result types, extensions, and validation utilities.
  • Yaver.Result.csproj — Project file for the library.

Getting Started

  1. Add a reference to the Yaver.Result project in your .NET solution.
  2. Use the provided result types (e.g., Result, PagedResult, ValidationError) in your application logic.
  3. Leverage extension methods for fluent result handling and validation integration.

Example Usage

Example of mapping a result to an HTTP response in ASP.NET Core:

public IActionResult MyAction()
{
    var result = DoSomething();
    return result.ToResponse(); // Uses ResultToResponse to map to the correct HTTP status code
}
using Yaver.Result;

public Result DoSomething()
{
    if (/* some error condition */)
        return Result.Error("An error occurred.");
    return Result.Success();
}
using MessagePack;
using MessagePack.Resolvers;
using Yaver.Result;

var options = MessagePackSerializerOptions.Standard
    .WithResolver(StandardResolver.Instance)
    .WithYaverResultResolver<MyDto>();

var serialized = MessagePackSerializer.Serialize(Result.Success(new MyDto()), options);
var deserialized = MessagePackSerializer.Deserialize<Result<MyDto>>(serialized, options);

License

This project is licensed under the MIT License.

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.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.1.0 324 4/30/2026
2.0.0 190 4/14/2026
1.1.0 3,051 11/18/2025
1.0.0 340 7/28/2025