Skip to main content
net8.0

A comprehensive Result type implementation for C# applications

Published
Nov 1, 2024
1y ago
Total Downloads
1.1K
1,108

Install

dotnet add package C0deGeek.Result --version 2.0.3
ProductVersions
.NET
net8.0

README

C0deGeek.Result

C0deGeek.Result is a library for handling and chaining the results of operations in a functional style.

Features

Represents the result of an operation as a Result or Result object.
Provides a fluent API for chaining operations and handling their results.
Distinguishes between different types of operation results, such as success, failure, and not found.

Usage

The following code snippets demonstrate the usage of this library:


using C0deGeek.Result;
using C0deGeek.Result.Extensions;

// ...

// Combine results
var combinedResult = Result.Ok()
.Combine(ValidateSomething(input))
.Combine(ValidateSomethingElse(input2));

// Throw on failure
combinedResult.ThrowFunctionalExceptionOnFailure();

// Extract value or throw on failure
var someClassValue = await GetSomeClassResult().GetValueOrThrowFunctionalException();

// On success, perform another operation
var finalResult = await GetSomeClassResult().OnSuccessAsync(value => PerformAnotherOperation(value));

Description of Methods

  • Combine: The Combine extension method allows you to chain multiple operations together. If any operation fails, the rest are not executed.
  • ThrowFunctionalExceptionOnFailure: The ThrowFunctionalExceptionOnFailure extension method throws a FunctionalException if the result represents a failure.
  • GetValueOrThrowFunctionalException: The GetValueOrThrowFunctionalException extension method extracts the value from a Result or throws a FunctionalException if the result represents a failure.
  • OnSuccessAsync: The OnSuccessAsync extension method allows you to chain another operation that should be performed only if the previous operation was successful.

Installation

Add a reference to the C0deGeek.Result NuGet package to your project.

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Commit your changes
  4. Push to the branch
  5. Create a Pull Request

License

License: MIT
This project is licensed under the MIT License - see the LICENSE.md file for details.

Changes from Previous Version

No structural changes between v2.0.1 and v2.0.3.

Adoption Assessment

Assess this package against its supported frameworks, license, maintenance signals and dependency graph before making it a project standard.

Compatibility metadata lists 1 target framework; confirm the exact target used by your application.

Related Guides & Workflows

Learn how to evaluate, integrate, or audit this package in your .NET project.