YDotNet.ResultType 2.0.0

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

🚀 ResultType

🌟 Overview

ResultType is a lightweight and powerful C# library designed to streamline structured handling of operation results in .NET applications. It provides a Result type that encapsulates success or failure outcomes, along with detailed error information. With built-in ASP.NET Core integration, it simplifies API response handling effortlessly.

🔗 NuGet Package: YDotNet.ResultType


✨ Features

✅ Strongly-typed Result and Result<T> for clear success/failure handling.
✅ Built-in error management with IError, Error, and ValidationError.
ASP.NET Core integration with ToHttpResult() for easy API responses.
✅ Utility methods like Match() for streamlined handling.
✅ Implicit conversions for clean and concise code.


📦 Installation

Add ResultType to your .NET project using:

 dotnet add package YDotNet.ResultType

🚀 Quick Start

✅ Basic Success & Failure Handling

using ResultType;
using ResultType.Errors;

Result successResult = Result.Success();
Result failureResult = Result.Failure(new Error("NotFound", "Item not found", 404));

if (failureResult.IsFailure)
{
    Console.WriteLine($"Error: {failureResult.Error?.Message}");
}

🔹 Handling Generic Results

var successWithValue = Result.Success("Hello, World!");
var failureWithValue = Result.Failure<string>(new Error("InvalidData", "The provided data is incorrect.", 400));

if (successWithValue.IsSuccess)
{
    Console.WriteLine(successWithValue.Value); // Outputs: Hello, World!
}

🌐 Converting to HTTP Results (ASP.NET Core)

IResult success = Result.Success("Hello, World!").ToHttpResult();
IResult failure = Result.Failure<string>(new Error("InvalidData", "The provided data is incorrect.", 400)).ToHttpResult();

🔄 Implicit Conversion

Result<string> result = "Implicit success"; // Automatically wraps value in Result.Success

🌍 ASP.NET Core Integration

🏗️ Using Result in Minimal APIs

using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using ResultType;
using ResultType.Errors;

var app = WebApplication.Create();

app.MapGet("/user/{id}", (int id) =>
{
    if (id <= 0)
        return Result.Failure(new Error("InvalidId", "User ID must be positive", 400)).ToHttpResult();

    return Result.Success(new { Id = id, Name = "John Doe" }).ToHttpResult();
});

app.Run();

⚠️ Error Handling

🛠️ Custom Error Handling

Error error = new Error("Forbidden", "You are not authorized to access this resource.", 403);
Result failure = Result.Failure(error);

📜 License

This project is licensed under the MIT License.


🤝 Contributing

We welcome contributions! Feel free to open issues or submit pull requests.

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
2.0.0 74 4/27/2025
1.0.1 177 3/8/2025