ReturnPattern 9.0.1
dotnet add package ReturnPattern --version 9.0.1
NuGet\Install-Package ReturnPattern -Version 9.0.1
<PackageReference Include="ReturnPattern" Version="9.0.1" />
<PackageVersion Include="ReturnPattern" Version="9.0.1" />
<PackageReference Include="ReturnPattern" />
paket add ReturnPattern --version 9.0.1
#r "nuget: ReturnPattern, 9.0.1"
#:package ReturnPattern@9.0.1
#addin nuget:?package=ReturnPattern&version=9.0.1
#tool nuget:?package=ReturnPattern&version=9.0.1
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 | Versions 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. |
-
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.