ReturnPattern 9.0.1

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

ReturnPattern

🚀ReturnPattern is a lightweight C#

Library designed for graceful operation result handling without using exceptions for control flow. It provides a clear and predictable way to return a value on success or error information on failure, leading to cleaner and more robust code. Who is this library for? This library is created for the entire C# and .NET world, offering a modern approach to handling results and errors in applications of any scale. If you strive for a more functional programming style and want to reduce reliance on try-catch blocks for handling expected failures, ReturnPattern is for you.

Installation

You can easily add ReturnPattern to your project using the NuGet Package Manager:

Install-Package ReturnPattern

Or via .NET CLI: dotnet add package ReturnPattern

Key

FeaturesExplicit Result Representation: Clearly indicates whether an operation succeeded IsSuccess or failed IsFailure, and provides access to Value or Error.Controlled Error Handling: Allows returning specialized exceptions or simple string messages on errors, giving you full control.Clean and Concise API: Simplifies result handling logic, making code more readable and maintainable. ReturnPattern offers three main Return types for different scenarios: with a value type and an error type, with only a value type with Exception as the default error, and without types for operations that simply indicate success/failure.

using ReturnPattern;
using System;

public class Program
{
    public static void Main(string[] args)
    {
        Console.WriteLine("--- Example Return<TValue, TError> ---");
        PatternResultTValueAndTError();

        Console.WriteLine("\n--- Example Return<TValue> ---");
        PatternResultTValue();

        Console.WriteLine("\n--- Example Return ---");
        PatternResult();
    }

    static void PatternResultTValueAndTError()
    {
        Return<double, DivideByZeroException> r = Divide(4.5, 7.8);

        if (r.IsSuccess)
        {
            Console.WriteLine($"Success: {r.IsSuccess}");
            Console.WriteLine($"Result: {r.Value}");
        }
        else
        {
            Console.WriteLine($"Error: {r.Message}");
        }
    }

    static void PatternResultTValue()
    {
        Return<int> r = IsSix(6);

        if (r.IsSuccess)
        {
            Console.WriteLine($"Success: {r.IsSuccess}");
            Console.WriteLine($"Result: {r.Value}");
        }
        else
        {
            Console.WriteLine($"Error: {r.Message}");
        }
    }

    static void PatternResult()
    {
        Return r = StringIsEmpty(string.Empty);

        if (r.IsSuccess)
        {
            Console.WriteLine($"Success: {r.IsSuccess}");
        }
        else
        {
            Console.WriteLine($"Error: {r.Message}");
        }
    }

    // Helper methods demonstrating Return usage
    static Return<double, DivideByZeroException> Divide(double a, double b)
    {
        if (b == 0)
        {
            return Return.Failure(new DivideByZeroException(), 0.0);
        }
        return Return.Success<double, DivideByZeroException>(a / b);
    }

    static Return<int> IsSix(int value)
    {
        if(value is 6)
        {
            return Return.Success(value);
        }

        return Return.Failure($"{value} is not 6", 0);
    }

    static Return StringIsEmpty(string value)
    {
        if(value == string.Empty)
        {
            return Return.Success();
        }

        return Return.Failure($"{value} is not empty");
    }
}

Release Notes (Brief Overview)

We've updated your library for improved reliability! The HasValue property is now deprecated; please use IsSuccess instead. IsSuccess logic is updated: it's now true only when Value is not null, ensuring its availability. Also, the Result class has been renamed to Return for better clarity in representing method outcomes. The implicit Return to bool conversion is deprecated too; check status using IsSuccess or IsFailure to always access error details. These changes make your code more predictable and safer.

🛠 Author: Fishman 📅 Last updated: July 2025

📄 License

This project is licensed under the Boost Software License – Version 1.0 – August 17th, 2003.

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 (1)

Showing the top 1 NuGet packages that depend on ReturnPattern:

Package Downloads
FirebaseExtensions

A library has been created to simplify data retrieval and uploading in Firestore.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
9.0.1 129 7/14/2025

V:9.0.1
We've updated your library for improved reliability! The HasValue property is now deprecated; please use IsSuccess instead. IsSuccess logic is updated: it's now true only when Value is not null, ensuring its availability. Also, the Result class has been renamed to Return for better clarity in representing method outcomes. The implicit Return to bool conversion is deprecated too; check status using IsSuccess or IsFailure to always access error details. These changes make your code more predictable and safer.