Etymon.Result.Extensions 1.3.0

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

Etymon.Result.Extensions

Etymon.Result.Extensions provides helper extensions for working with Etymon.Result, specifically for ASP.NET Core Web APIs. It simplifies controller code by converting Result<T> objects into appropriate HTTP responses using ToActionResult() or ToActionResultWithResult().


📦 Installation

dotnet add package Etymon.Result.Extensions

Requires: .NET 6.0 or higher and reference to Etymon.Result.


✨ Features

  • ToActionResult() for returning IActionResult in responses
  • ToActionResultWithResult() for returning full ActionResult<Result<T>> object in responses
  • Maps ResultCode (e.g. NotFound, ValidationError) to standard HTTP responses
  • Reduces repetitive error handling logic in controller actions

✅ How to Use

1. Add a reference to your service that returns Result<T>:

public async Task<Result<ItemDto>> GetItem(int id);

2. In your controller:

Using ToActionResult() (returns IActionResult)
using Etymon.Result.Extensions;

[HttpGet("{id}")]
public async Task<IActionResult> GetItem(int id)
{
    var result = await _itemService.GetItem(id);
    return result.ToActionResult();
}
Using ToActionResultWithResult() (returns full ActionResult<Result<T>> in responses)
[HttpGet("{id}")]
public async Task<ActionResult<Result<ItemDto>>> GetItem(int id)
{
    var result = await _itemService.GetItem(id);
    return result.ToActionResultWithResult();
}

3. Output Samples

✅ Success (HTTP 200):
{
  "data": {
    "id": 1,
    "name": "Sample Item"
  },
  "error": null,
  "isSuccess": true
}
❌ Failure (e.g. HTTP 404):
{
  "data": null,
  "error": {
    "code": "NotFound",
    "message": "Item was not found."
  },
  "isSuccess": false
}

🔧 How It Works

The ToActionResult() and ToActionResultWithResult() methods map ResultCode to standard HTTP results:

ResultCode HTTP Response
Success 200 OK
NotFound 404 Not Found
ValidationError 400 Bad Request
Unauthorized 403 Forbidden
Conflict 409 Conflict
InternalError 500 Internal Error

📌 Version History

  • 1.3.0
    • Added ToActionResultWithResult() to support full ActionResult<Result<T>> responses
  • 1.2.1 and earlier
    • Core implementation of ToActionResult() with clean HTTP response mappings

📄 License

MIT


🤝 Contributing

Feel free to open issues or submit PRs to extend support for non-generic Result, middleware integration, or advanced model binding.

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.3.0 151 5/29/2025
1.2.1 170 4/7/2025
1.2.0 96 4/5/2025
1.0.0 93 4/5/2025