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
<PackageReference Include="EventHorizon.Operations.Resulting" Version="1.0.0" />
paket add EventHorizon.Operations.Resulting --version 1.0.0
#r "nuget: EventHorizon.Operations.Resulting, 1.0.0"
// 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](https://github.com/lucasRafaell95/hrz-operations-resulting/actions/workflows/development-ci.yml/badge.svg)
This package contains a generic, extensible implementation of a base result class.
Package | Version | Downloads |
---|---|---|
EventHorizon.Operations.Resulting |
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 | Versions 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. 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. |
-
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 | 254 | 10/15/2022 |