EventHorizon.Operations.Resulting 1.0.0

dotnet add package EventHorizon.Operations.Resulting --version 1.0.0
NuGet\Install-Package EventHorizon.Operations.Resulting -Version 1.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="EventHorizon.Operations.Resulting" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add EventHorizon.Operations.Resulting --version 1.0.0
#r "nuget: EventHorizon.Operations.Resulting, 1.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.
// Install EventHorizon.Operations.Resulting as a Cake Addin
#addin nuget:?package=EventHorizon.Operations.Resulting&version=1.0.0

// Install EventHorizon.Operations.Resulting as a Cake Tool
#tool nuget:?package=EventHorizon.Operations.Resulting&version=1.0.0

Event Horizon Resulting Library resulting

This package contains a generic, extensible implementation of a base result class.

Package Version Downloads
EventHorizon.Operations.Resulting NuGet Nuget

Installation

The EventHorizon.Operations.Resulting package is available on Nuget. You can use it in the following ways:

  • Package Manager
PM> NuGet\Install-Package EventHorizon.Operations.Resulting -Version 1.0.0
  • .NET Cli
dotnet add package EventHorizon.Operations.Resulting --version 1.0.0
  • PackageReference
<PackageReference Include="EventHorizon.Operations.Resulting" Version="1.0.0" />

How to use

  • Result

Result was developed to encompass the result of operations in a generic and extensible way. With it it is possible to return from these literal types, such as an int for example, to complex objects.

public Result<string> GetFullName(string firstName, string lastName)
{
   var fullName = firstName + lastName;

   return new Result<string>(fullName);
}
  • Error

It is also possible to specify an error object to signal/return the status of an operation. Essentially, an error has two properties: code and a message. To use it, just do as in the example below:

public Result<float> DivideNumber(float dividend, float divisor)
{
   if(divisor <= 0)
   {
       var error = new Error("400-1", "You can never divide by zero");

       return new Result<float>(error);
   }

   var result = dividend / divisor;

   return new Result<float>(result);
}

The Result contains the WithError() extension method that encapsulates the error creation logic. To use it, just do as in the following example:

public Result<string> GetFullName(string firstName, string lastName)
{
   var result = new Result<string>();

   if(string.IsNullOrEmpty(firstName))
	{
       return result.WithError("400-1", "Invalid first name");
	}

   if(string.IsNullOrEmpty(lastName))
	{
       return result.WithError("400-2", "Invalid last name");
	}

   result = firstName + lastName;

   return result;
}
Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net6.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.0 216 10/15/2022