ExecutionResults 0.1.0

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

// Install ExecutionResults as a Cake Tool
#tool nuget:?package=ExecutionResults&version=0.1.0                

ExecutionResults

The dotnet library, which adds types of operation results and provides a convenient way to return an error instead of creating an exception.

The ExecutionResults library introduces several result types that you can use to represent the outcome of an operation. These types include:

  1. Option<TValue>
  2. Result<TError>
  3. Result<TValue, TError> To use these result types, you can include the ExecutionResults namespace in your code:
using ExecutionResults;

Using the Option<TValue> type

The Option<TValue> type must be used when the method may not return a result, while not generating any errors.

    /// Shortened record of the return of the found value.
    public Option<int> FindValue()
    {
        // implementation of the int type value search
        return foundValue;
    }
    
    /// An example when the method could not find a value with the int type, and it is necessary to return none
    public Option<int> FindValue()
    {
        // implementation of the int type value search
        return Option<int>.None();
    }
    
    /// An example of using the received Option<int> from the FindValue method
    public void Main()
    {
        var foundValue = FindValue();
        var resultMessage = foundValue.Map(
            some: value => $"The found value is '{value}'", 
            none: () => "The value was not found");
        
        Console.WriteLine(resultMessage);
    }

Using the Result<TError> type

The Result<Error> type should be used when the method should not return a result, while generating an error in case of failure.

    /// you can declare your own error types
    public record SampleInvocationError() : Error("The value could not be calculated");

    /// An example of a method with a return success result.
    public Result<Error> Invoke()
    {
        // method implementation
        return Result<Error>.Ok();
    }

    /// Shortened record of the return of the error.
    public Result<SampleInvocationError> Invoke()
    {
        // method implementation
        return new SampleInvocationError();
    }
    
    /// An example of using the received Result<Error> from the Invoke method
    public void Main()
    {
        var invocationResult = Invoke();
        if (invocationResult.IsFailure)
        {
            Console.WriteLine(invocationResult.Error.Message);
            return;
        }
        
        // some logic
    }

Using the Result<TValue, TError> type

The Result<TValue, TError> type should be used when the method should return a result, while generating an error in case of failure.

    /// you can declare your own error types
    public record EntityNotFoundError() : Error("Entity not found");
    public record AccessDeniedError() : Error("There are not enough permissions to perform the operation");

    /// An example of a method with a shortened return custom error.
    public Result<Guid, Error> Handle()
    {
        if (!IsAdmin())
        {
            return new AccessDeniedError();
        }
        // method implementation
    }

    /// An example of a method with a return success result.
    public Result<Guid, Error> Handle()
    {
        // method implementation
        return entity.Id;
    }
    
    /// An example of using the received Result<Value, Error> from the Handle method with http response mapping
    public IActionResult SomeMethod()
    {
        var result = Handle();
        return result.Map(
            onSuccess: id => new OkObjectResult(id),
            onFailure: error => error switch {
                EntityNotFoundError => new NotFoundObjectResult(error.Message),
                AccessDeniedError => new ForbidResult(),
            });
    }
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.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
0.1.0 171 3/13/2024