VOOZH about

URL: https://www.nuget.org/packages/MadEyeMatt.Results.AspNetCore/

⇱ NuGet Gallery | MadEyeMatt.Results.AspNetCore 2.1.0




👁 Image
MadEyeMatt.Results.AspNetCore 2.1.0

Suggested Alternatives

Fluxera.Results.AspNetCore

Additional Details

The project was moved to the Fluxera Foundation.

dotnet add package MadEyeMatt.Results.AspNetCore --version 2.1.0
 
 
NuGet\Install-Package MadEyeMatt.Results.AspNetCore -Version 2.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="MadEyeMatt.Results.AspNetCore" Version="2.1.0" />
 
 
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="MadEyeMatt.Results.AspNetCore" Version="2.1.0" />
 
Directory.Packages.props
<PackageReference Include="MadEyeMatt.Results.AspNetCore" />
 
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 MadEyeMatt.Results.AspNetCore --version 2.1.0
 
 
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: MadEyeMatt.Results.AspNetCore, 2.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 MadEyeMatt.Results.AspNetCore@2.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=MadEyeMatt.Results.AspNetCore&version=2.1.0
 
Install as a Cake Addin
#tool nuget:?package=MadEyeMatt.Results.AspNetCore&version=2.1.0
 
Install as a Cake Tool
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

Results

A result object implementation. Return result objects from operations to indicate success or failure instead of throwing exceptions.

Features

  • Default result implementations with and without a result value.
    • Result
    • Result<int>
  • Supports multiple error messages.
  • Supports optional multiple success messages.
  • Supports custom error and success implementations.
  • Provides FluentAssertions extensions for simpler unit testing.
  • Provides extensions to transform results to IActionResult instances for ASP.NET controllers.
  • Provides extensions to transform results to IResult instances to be used with Minimal APIs.

Usage

Create Results

To create result instances use the static helper methods found in the Result class.

// Create a successful result without a value.
Result result = Result.Ok();

// Create a successful result with a value.
Result<int> result = Result.Ok(42);

// Create a failed result without a value.
Result result = Result.Fail("An error occurred.");
Result result = Result.Fail(new Error("An error occurred));

// Create a failed result for a result that can have a value.
Result<int> result = Result.Fail<int>("An error occurred.");
Result<int> result = Result.Fail<int>(new Error("An error occurred));

The result type Result is typically used by operations that have no return value.

public Result PerformOperation() 
{
 if(this.State == State.Failed) 
 {
 return Result.Fail("The operation failed.");
 }

 return Result.Ok();
}

The result type Result<T> is typically used by operations that have a return value.

public Result<int> PerformOperation() 
{
 if(this.State == State.Failed) 
 {
 return Result.Fail<int>("The operation failed.");
 }

 return Result.Ok(42);
}

Process Results

To process the result of an operation you can check if the operation was successful or failed by accessing the IsSuccessful or IsFailed properties.

// Handle the return value of a result without a value.
Result result = PerformOperation();

// Print all error messages, if the result is failed.
if(result.IsFailed) 
{
 foreach(IError error in result.Errors) 
 {
 Console.WriteLine(error.Message);
 }
}

// Print all success messages, if the result is successful.
if(result.IsSuccessful) 
{
 foreach(ISuccess success in result.Successes) 
 {
 Console.WriteLine(success.Message);
 }
}

// Handle the return value of a result with a value.
Result<int> result = PerformOperation();

// Get the value if the result is successful or will throw if the result is failed.
int value = result.Value;

// Get the value oif the result is successful or will return the default of the value.
int value = result.GetValueOrDefault();

References

Michael Altmann

FluentResults

Product Versions Compatible and additional computed target framework versions.
.NET net6.0 net6.0 is compatible.  net6.0-android net6.0-android was computed.  net6.0-ios net6.0-ios was computed.  net6.0-maccatalyst net6.0-maccatalyst was computed.  net6.0-macos net6.0-macos was computed.  net6.0-tvos net6.0-tvos was computed.  net6.0-windows net6.0-windows was computed.  net7.0 net7.0 is compatible.  net7.0-android net7.0-android was computed.  net7.0-ios net7.0-ios was computed.  net7.0-maccatalyst net7.0-maccatalyst was computed.  net7.0-macos net7.0-macos was computed.  net7.0-tvos net7.0-tvos was computed.  net7.0-windows net7.0-windows was computed.  net8.0 net8.0 is compatible.  net8.0-android net8.0-android was computed.  net8.0-browser net8.0-browser was computed.  net8.0-ios net8.0-ios was computed.  net8.0-maccatalyst net8.0-maccatalyst was computed.  net8.0-macos net8.0-macos was computed.  net8.0-tvos net8.0-tvos was computed.  net8.0-windows net8.0-windows was computed.  net9.0 net9.0 was computed.  net9.0-android net9.0-android was computed.  net9.0-browser net9.0-browser was computed.  net9.0-ios net9.0-ios was computed.  net9.0-maccatalyst net9.0-maccatalyst was computed.  net9.0-macos net9.0-macos was computed.  net9.0-tvos net9.0-tvos was computed.  net9.0-windows net9.0-windows was computed.  net10.0 net10.0 was computed.  net10.0-android net10.0-android was computed.  net10.0-browser net10.0-browser was computed.  net10.0-ios net10.0-ios was computed.  net10.0-maccatalyst net10.0-maccatalyst was computed.  net10.0-macos net10.0-macos was computed.  net10.0-tvos net10.0-tvos was computed.  net10.0-windows 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.1.0 321 4/24/2024 2.1.0 is deprecated because it is no longer maintained.
2.0.2 197 4/19/2024
2.0.1 192 4/18/2024
2.0.0 181 4/18/2024
1.2.0 214 3/19/2024