MResulPattern 1.0.1

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

ResultPattern for .NET

NuGet Downloads NuGet Version NuGet Pre-release Version License

A robust implementation of the Result pattern for .NET applications, providing a standardized way to handle operation outcomes with proper status codes and error handling.

Key Features

  • Structured responses for both success and failure cases
  • Strongly-typed results with generic support
  • HTTP status code integration
  • Comprehensive error handling with multiple message support
  • JSON-ready serialization for API responses
  • Fluent API for clean result handling

Installation

dotnet add package MResulPattern

Usage

Successful Operation
var success = Result<Customer>.Success(new Customer { Id = 1, Name = "John" });
Failed Operation
var failure = Result<Customer>.Failure(404, "Customer not found");
Web API Integration
[HttpGet("{id}")]
public IActionResult GetCustomer(int id)
{
    var customer = _repository.Get(id);
    return customer != null 
        ? Ok(Result<Customer>.Success(customer))
        : NotFound(Result<Customer>.Failure(404, "Not found"));
}
Fluent Handling
var result = _service.ProcessOrder()
    .OnSuccess(order => _logger.LogInformation($"Processed order {order.Id}"))
    .OnFailure(errors => _logger.LogError($"Failed: {string.Join(", ", errors)}"));
Multiple Errors
var errors = new List<string> { "Invalid email", "Missing required field" };
var result = Result<User>.Failure(400, errors);

API Reference

Result<T>
T? Data - Operation data (null when failed)

List<string>? ErrorMessages - Error collection

int StatusCode - HTTP status code

bool IsSuccess - Success indicator

Static Methods:

Success(T data, int statusCode = 200)

Failure(int statusCode, List<string> errorMessages)

Failure(int statusCode, string errorMessage)

Failure(string errorMessage) (defaults to 500)
Result
List<string>? ErrorMessages

int StatusCode

bool IsSuccess

Static Methods:

Success(int statusCode = 200)

Failure(int statusCode, List<string> errorMessages)

Failure(int statusCode, string errorMessage)

Failure(string errorMessage)
Product Compatible and additional computed target framework versions.
.NET 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net9.0

    • No dependencies.

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 140 10 days ago
1.0.0 127 11 days ago

result Nugget Package