lcsoft.results

Result pattern implementation

https://github.com/luigi-sw/lcsoft.results

Science Score: 44.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
    Found CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
  • Academic publication links
  • Academic email domains
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (10.1%) to scientific vocabulary
Last synced: 6 months ago · JSON representation ·

Repository

Result pattern implementation

Basic Info
  • Host: GitHub
  • Owner: luigi-sw
  • License: other
  • Language: C#
  • Default Branch: master
  • Size: 252 KB
Statistics
  • Stars: 1
  • Watchers: 0
  • Forks: 0
  • Open Issues: 1
  • Releases: 3
Created 9 months ago · Last pushed 6 months ago
Metadata Files
Readme Contributing Funding License Code of conduct Citation Codeowners Security Support

README.md

LCSoft: Results Pattern for .NET

A robust, flexible, and type-safe result and error handling library for .NET applications. Provides unified success/failure result types with rich error information and functional pattern matching for clean, expressive code.

NuGet License: CC BY-NC-ND 4.0


Features

  • Unified result types for success/failure handling
  • Generic Results<TValue> and non-generic Results classes
  • Simplified alternative via sResults<TValue> and sResults using the lightweight Error record
  • Encapsulation of success value or error with rich error details
  • Functional Match methods supporting both Func and Action delegates
  • Implicit conversion operators for easy construction from values or errors
  • Abstract ErrorsType base class with error code, name, and registry
  • Standard predefined error types via StandardErrorType
  • Detailed Error record with error code, message, and categorized error type
  • ErrorType enum classifying error categories
  • Interfaces IResult<TError> and IResult with default implementations
  • Explicit interface implementations for polymorphic usage
  • Centralized error code registry and lookup by code
  • Nullable callback support in Match methods
  • Designed for testability and code coverage compatibility
  • Extensible architecture for custom error and result handling
  • Suitable for layered and domain-driven design applications

Installation

Install via NuGet:

bash dotnet add package LCSoft.Results

Or via Package Manager:

bash Install-Package LCSoft.Results

Quick Start

Basic Usage

```csharp using LCSoft.Results;

Results result = DoSomething();

if (result.IsSuccess) { Console.WriteLine("Success!"); } else { Console.WriteLine($"Failed: {result.Error}"); } ```

With a Value

```csharp Results result = Calculate();

if (result.IsSuccess) { int value = result.Value; Console.WriteLine($"Result: {value}"); } else { Console.WriteLine($"Error: {result.Error}"); } ```

Non-generic Result

```csharp Results result = Results.Success();

result.Match( success: () => Console.WriteLine("Operation succeeded!"), failure: error => Console.WriteLine($"Failed with error: {error.Name}") ); ```

Generic Result with Value

```csharp Results result = 42; // implicit success

int value = result.Match( onSuccess: val => val * 2, onFailure: error => -1 ); Console.WriteLine(value); // 84 ```

Handling Errors

```csharp var error = StandardErrorType.Validation; Results failureResult = Results.Failure(error);

failureResult.Match( success: () => Console.WriteLine("This won't be called."), failure: err => Console.WriteLine($"Validation failed: {err.Name}") ); ```

Using sResults and sResults

For lighter scenarios, you can use sResults and sResults<T> which use a simplified Error record structure.

```csharp sResults result = 10;

result.Match( success: val => Console.WriteLine($"Success with value {val}"), failure: err => Console.WriteLine($"Failed with code {err.Code}") ); ```

Extending Errors

```csharp public sealed class CustomErrorType : ErrorsType { public static readonly CustomErrorType CustomFailure = new(100, "CustomFailure");

private CustomErrorType(int code, string name) : base(code, name)
{
    Register(this);
}

} ```

Use ErrorsType.FromCode(code) to retrieve error types dynamically.

Interfaces

  • IResult<TError> for basic result contracts
  • IResult for generic result contracts
  • Both provide functional Match methods with success and failure delegates

Example

csharp Results<int> ParseNumber(string input) { if (int.TryParse(input, out int number)) return Results<int>.Success(number); return Results<int>.Failure(StandardErrorType.GenericFailure); }

License

This project is licensed under the CC-BY-NC-ND-4.0 License. See the LICENSE file for details.

Contributing

Contributions are welcome! Please open issues or submit pull requests on GitHub.

Owner

  • Name: luigi-sw
  • Login: luigi-sw
  • Kind: organization

Citation (CITATION.cff)

cff-version: 1.2.0
message: "If you use this software, please cite it as below."
type: software
authors:
  - family-names: C. Filho
    given-names: Luigi
    portfolio: https://www.lcdesenvolvimentos.com.br
title: "Repo"
version: 0.1.2
date-released: 2025-03-07
url: "https://github.com/luigi-sw/LCSoft.Results"

GitHub Events

Total
  • Release event: 9
  • Delete event: 13
  • Push event: 31
  • Gollum event: 5
  • Pull request event: 7
  • Create event: 16
Last Year
  • Release event: 9
  • Delete event: 13
  • Push event: 31
  • Gollum event: 5
  • Pull request event: 7
  • Create event: 16

Issues and Pull Requests

Last synced: 6 months ago

All Time
  • Total issues: 0
  • Total pull requests: 5
  • Average time to close issues: N/A
  • Average time to close pull requests: less than a minute
  • Total issue authors: 0
  • Total pull request authors: 2
  • Average comments per issue: 0
  • Average comments per pull request: 0.0
  • Merged pull requests: 2
  • Bot issues: 0
  • Bot pull requests: 3
Past Year
  • Issues: 0
  • Pull requests: 5
  • Average time to close issues: N/A
  • Average time to close pull requests: less than a minute
  • Issue authors: 0
  • Pull request authors: 2
  • Average comments per issue: 0
  • Average comments per pull request: 0.0
  • Merged pull requests: 2
  • Bot issues: 0
  • Bot pull requests: 3
Top Authors
Issue Authors
Pull Request Authors
  • dependabot[bot] (3)
  • luigicfilho (2)
Top Labels
Issue Labels
Pull Request Labels
dependencies (3) .NET (3)

Packages

  • Total packages: 1
  • Total downloads:
    • nuget 459 total
  • Total dependent packages: 0
  • Total dependent repositories: 0
  • Total versions: 3
  • Total maintainers: 1
nuget.org: lcsoft.results

Implementation the Results Pattern for .NET API applications.

  • Versions: 3
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Downloads: 459 Total
Rankings
Dependent repos count: 6.7%
Dependent packages count: 18.1%
Average: 27.2%
Downloads: 56.7%
Maintainers (1)
Last synced: 6 months ago

Dependencies

LCSoft.Results/LCSoft.Results.csproj nuget