NTResult 1.1.0

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

<p align="center"> <img src="Logo.png" alt="NTResult Logo" width="128" height="128" /> </p>

NTResult Solution

NTResult is a .NET solution providing a set of libraries for handling result types, error handling, and HTTP integration in C# applications. It is designed to improve code clarity, error propagation, and integration with ASP.NET Core and Refit-based APIs.

Table of Contents


Projects Overview

1. NTResult

  • Purpose:
    • Core library for result types (Expected, Optional, etc.), error handling, and utility extensions.
    • Provides a functional approach to handling success/failure and optional values.
  • Key Files:
    • Expected.cs, Optional.cs, NTResult.cs, NTFileDownload.cs
    • Extensions in Ext/
    • Custom exceptions in Exceptions/

2. NTResult.AspNetCore.Http

  • Purpose:
    • Integrates NTResult types with ASP.NET Core HTTP pipeline.
    • Provides helpers for controller responses and HTTP result mapping.
  • Key Files:
    • NTResultControllerBase.cs, HttpNTResult.cs
    • Extensions in Ext/

3. NTResult.Refit

  • Purpose:
    • Adds support for using NTResult types with Refit (a REST library for .NET).
    • Provides extension methods for working with IApiResponse and mapping API results.
  • Key Files:
    • Extensions in Ext/

4. NTResult.Tests

  • Purpose:
    • Contains unit tests for all core and extension libraries.
    • Organized by subproject and feature.

Build Instructions

  1. Prerequisites:

  2. Restore dependencies:

    dotnet restore NTResult.slnx
    
  3. Build the solution:

    dotnet build NTResult.slnx --configuration Release
    

Running Tests

All tests are located in the NTResult.Tests project. To run all tests:

dotnet test NTResult.slnx

Usage Examples

NTResult

using NTResult;

// --- Expected usage ---
var ok = Expected.MakeExpected<int, string>(42);
if (ok.HasValue)
{
    Console.WriteLine($"Value: {ok.Value}");
}
else
{
    Console.WriteLine($"Error: {ok.Error}");
}

var err = Expected.MakeUnexpected<int, string>("Something went wrong");
if (!err.HasValue)
{
    Console.WriteLine($"Error: {err.Error}");
}

// --- Optional usage ---
var some = Optional.MakeOptional("hello");
if (some.HasValue)
{
    Console.WriteLine($"Optional value: {some.Value}");
}

var none = Optional.NullOpt<string>();
if (none.IsEmpty)
{
    Console.WriteLine("Optional is empty");
}

// --- INTResult usage ---
INTResult result = NTResult.Successful;
result
    .OnSuccess(() => Console.WriteLine("Operation succeeded!"))
    .OnFailure(ex => Console.WriteLine($"Operation failed: {ex.Message}"))
    .Finally(() => Console.WriteLine("Operation finished (success or failure)"));

// INTResult<T> usage
INTResult<string> result2 = NTResult.Success("Hello");
result2
    .OnSuccess(val => Console.WriteLine($"Success value: {val}"))
    .OnFailure(ex => Console.WriteLine($"Failed: {ex.Message}"))
    .Finally(() => Console.WriteLine("Done!"));

// --- Async usage with extension methods ---
using NTResult.Ext;
await Task.FromResult(NTResult.Successful)
    .OnSuccessAsync(() => Console.WriteLine("Async success!"));

await Task.FromResult(NTResult.Failure(new Exception("fail")))
    .OnFailureAsync(ex => Console.WriteLine($"Async failure: {ex.Message}"));

NTResult.AspNetCore.Http

using NTResult.AspNetCore.Http;
using NTResult;
using Microsoft.AspNetCore.Mvc;

// Inherit from NTResultControllerBase to use static helpers
// Return INTResult from your actions—the base class will automatically convert it to an appropriate IResult for ASP.NET Core.
public class MyController : NTResultControllerBase
{
    [HttpGet("/created")]
    public INTResult CreatedExample()
    {
        // Use the static SuccessfullyCreated property
        return SuccessfullyCreated;
    }

    [HttpGet("/forbidden")]
    public INTResult ForbiddenExample()
    {
        // Use the static FailureForbidden property
        return FailureForbidden;
    }

    [HttpGet("/conflict")]
    public INTResult ConflictExample()
    {
        // Use the static Conflict helper
        return Conflict("A conflict occurred");
    }

    [HttpGet("/custom-created")]
    public INTResult CustomCreatedExample()
    {
        // Use the static Created<T> helper for a custom value
        return Created("Resource created!");
    }
}

// Note: NTResultControllerBase will automatically convert any INTResult returned from your action
// into the correct ASP.NET Core IResult (status code, body, etc.) for the HTTP response.

NTResult.Refit

using NTResult.Refit.Ext;
using Refit;

public interface IMyApi
{
    [Get("/data")]
    Task<IApiResponse<string>> GetDataAsync();
}

// Usage in your code:
var apiResponse = await myApi.GetDataAsync();
var result = apiResponse.ToNTResult();
if (result.IsSuccess)
{
    Console.WriteLine($"API value: {result.Value}");
}
else
{
    Console.WriteLine($"API error: {result.Error.Message}");
}

License

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

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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net10.0

    • No dependencies.
  • net8.0

    • No dependencies.
  • net9.0

    • No dependencies.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on NTResult:

Package Downloads
NTResult.AspNetCore.Http

ASP.NET Core integration for NTResult, providing seamless result handling and controller extensions for web APIs.

NTResult.Refit

Refit integration for NTResult, enabling functional result types in Refit-based HTTP clients for .NET.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.1.0 318 6/8/2026
1.1.0-preview.1 68 6/8/2026
1.0.0 129 5/29/2026