OpenResult 1.0.0

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

OpenResult for C#

Dead-simple, dependency-free Result pattern for .NET and C#.


API

Result

Represents the outcome of an operation—either success or failure.

Properties:

  • IsSuccess: true if the operation succeeded.
  • IsFailure: true if the operation failed.
  • Error?: The associated Error object if failed, or null if successful.

Methods:

  • Succeeded(): Returns true if successful (same as IsSuccess).
  • Failed(): Returns true if failed (same as IsFailure).
  • Failed(out Error? error): Returns true if failed, and outputs the associated Error object.

Static Methods:

  • Success(): Creates a successful result.
  • Success(TValue value): Creates a successful result for Result<TValue>. <br/>Sugar syntax for result creation with a value—type is inferred from the value.
  • Failure(Error error): Creates a failed result with an associated error.
  • Failure<TValue>(Error error): Creates a failed result for Result<TValue>.

Type Inference in C#

C# allows for sugar syntax like Result.Success(value) because it can deduce the type from the value provided. However, it cannot infer the type for failures from just the error object.

You must specify the type explicitly, for example:

Result<int>.Failure(error);
// or
Result.Failure<int>(error);
Workaround for Clean Calls

If you want to avoid repeating the type at every failure, you can use a local helper method:

private Result<MyType> Fail(Error error) => Result<MyType>.Failure(error); // <-- Helper

// Usage:
if (shouldFail) return Fail(new Error("failed!"));
return Result.Success(0);

This is a C# language limitation, not a library design issue. C# cannot automatically infer the return type from the consuming method's signature—it can only do so when a value is provided.

This will not compile:

private Result<int> MyMethod()
{
    //...
    return Result.Failure(new Error("failed!")); // Compilation error!
    // Result.Failure returns a non-generic Result, not a Result<int>.

    // ---
    // Correct usage:
    return Result<int>.Failure(new Error("failed!"));
    // or
    return Result.Failure<int>(new Error("failed!"));
}

Result<TValue> (Generic Version)

All of the above, plus:

Property:

  • Value: The value produced by a successful operation, or default if failed.

Method:

  • Succeeded(out TValue? value): Returns true if successful, and outputs the value.

Error

Describes an error condition in a structured, chainable way.

Properties:

  • Message: Human-readable error message.
  • Code: Optional code/identifier for programmatic handling.
  • Exception: Optional Exception instance if error was caused by an exception.
  • InnerError: Optional reference to another Error that caused this error.
  • Root: The deepest, original error in a chain of errors.

Methods:

  • IsExceptional(): Returns true if this error wraps an Exception.
  • IsExceptional(out Exception? exception): Returns true and outputs the wrapped exception if present.
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

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
1.0.0 146 5/21/2025