4q-dev.ResultSharp 1.0.20

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

ResultSharp

A functional-style library for working with the Result pattern. Simplifies handling success and failure results without using exceptions, improving code readability and reliability.

ResultSharp

Documentation

Full documentation is available here: ResultSharp Docs

Features

  • Convenient representation of successful (Success) and failed (Failure) results
  • Composition and transformation of results using functional methods (Map, Then, Match, etc.)
  • Eliminates the need to use try-catch in business logic
  • Support for asynchronous operations
  • Support for logging: Microsoft.Extensions.Logging, Serilog, or any other custom adapter

Quick Start

Installation

dotnet add package 4q-dev.ResultSharp

Basic usage

using ResultSharp;
using ResultSharp.Errors;
using ResultSharp.Extensions.FunctionalExtensions.Sync;

Result<int> ParseNumber(string input)
{
    return int.TryParse(input, out var number)
        ? number
        : Error.Failure("Invalid number");
}

int result = ParseNumber("42")
    .Map(n => n * 2)
    .Match(
        ok => Console.Write($"Success: {ok}"), // output: Success: 84
        error => Console.Write($"Error: {error}")
    )
    .UnwrapOrDefault(@default: 0);

Console.WriteLine(result); // 84

Example Usage

Without using Result:

var user = userRepository.Get();
if (user is null)
{
    logger.LogMessage("User not found");
    throw new Exception("User not found");
}

if (user.Email.IsConfirmed is false)
{
    logger.LogMessage("Email address must be confirmed before sending notifications.");
    throw new Exception("Email address must be confirmed before sending notifications.");
}

try
{
    emailNotificationService.Notify(user.Email, "some notification message");
}
catch (Exception ex)
{
    Logger.LogMessage("Error message: {ex}", ex.Message);
    throw ex;
}

Using ResultSharp:

return userRepository.Get()
    .Ensure(user => user.Email.IsConfirmed, onFailure: Error.Unauthorized("Email address must be confirmed before sending notifications."))
    .Then(user => emailNotificationService.Notify(user.Email, "some notification message"))
    .LogIfFailure();

Contribution

We welcome contributions to the development of this library! To make changes:

  1. Fork the repository
  2. Create a new branch (git checkout -b feature-branch)
  3. Make changes and commit them (git commit -m 'Added new feature')
  4. Push the changes (git push origin feature-branch)
  5. Open a Pull Request

License

This project is licensed under the MIT License. See the LICENSE file for details.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  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.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net8.0

    • No dependencies.

NuGet packages (3)

Showing the top 3 NuGet packages that depend on 4q-dev.ResultSharp:

Package Downloads
4q-dev.ResultSharp.Logging.Serilog

Библиотека Result паттерна с функциональными методами

4q-dev.ResultSharp.Logging.MicrosoftLogger

Библиотека Result паттерна с функциональными методами

4q-dev.ResultSharp.HttpResult

Транслятор результата в HTTP ответ

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.20 155 5/1/2025
1.0.19 201 3/30/2025
1.0.18 149 3/28/2025
1.0.17 134 3/28/2025
1.0.16 152 3/16/2025
1.0.15 189 3/13/2025
1.0.14 163 3/11/2025
1.0.13 170 3/9/2025
1.0.12 155 3/8/2025
1.0.11 141 3/8/2025
1.0.10 147 3/8/2025
1.0.9 181 3/8/2025
1.0.8 210 3/7/2025
1.0.7 216 3/7/2025
1.0.6 117 2/15/2025
1.0.5 116 2/15/2025
1.0.4 187 2/15/2025
1.0.3 131 2/13/2025
1.0.2 209 2/10/2025