IntraDotNet.Results 1.0.0

The owner has unlisted this package. This could mean that the package is deprecated, has security vulnerabilities or shouldn't be used anymore.
dotnet add package IntraDotNet.Results --version 1.0.0
                    
NuGet\Install-Package IntraDotNet.Results -Version 1.0.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="IntraDotNet.Results" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="IntraDotNet.Results" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="IntraDotNet.Results" />
                    
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 IntraDotNet.Results --version 1.0.0
                    
#r "nuget: IntraDotNet.Results, 1.0.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.
#:package IntraDotNet.Results@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=IntraDotNet.Results&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=IntraDotNet.Results&version=1.0.0
                    
Install as a Cake Tool

IntraDotNet.Results

A standalone library for simple Result pattern implementation.

Overview

The Result and ValueResult classes provide a functional approach to error handling, eliminating the need for exceptions in many scenarios. They represent operations that can either succeed with a value or fail with an error.

Result Class

Basic Usage

// Success case
var successResult = Result.Success();

// Failure case
var failureResult = Result.Failure("Something went wrong");

// Check if operation succeeded
if (result.IsSuccess)
{
    Console.WriteLine(result.Value);
}
else
{
    Console.WriteLine(result.AggregateErrors);
}

Properties

  • IsSuccess: Boolean indicating if the operation succeeded
  • IsFailure: Boolean indicating if the operation failed
  • AggregateErrors: A line new delimited string of error messages (only populated when IsFailure is true)
  • Errors: A collection of error messages (only populated when IsFailure is true)

ValueResult<T> Class

Basic Usage

// Success case
var successResult = ValueResult<int>.Success(42);

// Failure case
var failureResult = ValueResult<int>.Failure("Invalid input");

// Implicit conversion from value
ValueResult<string> result = "Hello"; // Implicit failure

Key Differences from Result

Results is intended to be used for results returned from functions that would otherwise be void. ValueResult is intended to be used where a return value is expected.

Try-Parse Pattern

public ValueResult<int> TryParseInt(string input)
{
    if (int.TryParse(input, out int result))
        return ValueResult<int>.Success(result);
    
    return ValueResult<int>.Failure($"'{input}' is not a valid integer");
}

License

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

Contributing

Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.

Guidelines

  • Ensure any install or build dependencies are removed before the end of the layer when doing a build
  • Update the README.md with details of changes to the interface
  • Increase the version numbers and the README.md to the new version that this Pull Request would represent
  • You may merge the Pull Request in once you have the sign-off of an other developer, or if you do not have permission to do that, you may request the reviewer to merge it for you
Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  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.
  • net9.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