ResultWrapper 1.0.1

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

ResultHandling# Result Handling

NuGet License

Overview

Result Handling is a lightweight library for implementing the Result<T> pattern in .NET applications. It simplifies error handling and response management in ASP.NET Core APIs by providing a clean and consistent way to represent operation results with HTTP status codes, error messages, and seamless integration with ActionResult.

Features

  • Generic and Non-Generic Results: Supports both Result<T> (for operations returning a value) and Result (for operations without a return value).
  • Error Handling: Includes error messages and HTTP status codes for failed operations.
  • ASP.NET Core Integration: Provides extension methods to convert results into IActionResult for clean API responses.
  • .NET 8 Support: Fully compatible with .NET 8 and C# 12.

Installation

You can install the library via NuGet:

dotnet add package ResultWrapper

Or add the following to your .csproj file:

<PackageReference Include="ResultWrapper" Version="1.0.0" />

Usage

1. Using Result<T>

For operations that return a value:

using ResultHandling.Models;

public Result<string> GetGreeting(bool isSuccess)
{
    if (isSuccess)
    {
        return Result<string>.Success("Hello, World!");
    }

    return Result<string>.Failure("An error occurred.", 400);
}

2. Using Result

For operations that do not return a value:

using ResultHandling.Models;

public Result PerformOperation(bool isSuccess)
{
    if (isSuccess)
    {
        return Result.Success();
    }

    return Result.Failure("Operation failed.", 500);
}

3. Converting to IActionResult in ASP.NET Core

Use the provided extension methods to convert Result or Result<T> into IActionResult:

using Microsoft.AspNetCore.Mvc;
using ResultHandling.Models;
using ResultHandling.Extensions;

[ApiController]
[Route("api/[controller]")]
public class ExampleController : ControllerBase
{
    [HttpGet]
    public IActionResult GetExample(bool isSuccess)
    {
        var result = isSuccess
            ? Result<string>.Success("Data retrieved successfully.")
            : Result<string>.Failure("Failed to retrieve data.", 404);

        return result.ToActionResult();
    }
}

4. Handling Errors

You can include multiple error messages for failed operations:

var errors = new List<string> { "Error 1", "Error 2" };
var result = Result<string>.Failure(errors, 400);

Metadata

License

This project is licensed under the MIT License. See the LICENSE file for details.

Contributing

Contributions are welcome! Feel free to open issues or submit pull requests to improve the library.


Happy coding!

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 was computed.  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 was computed.  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
1.0.1 178 7/30/2025
1.0.0 584 7/22/2025