TeymurDevv.ResultPattern 1.0.0

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

TeymurDevv.ResultPattern

A lightweight and elegant Result Pattern implementation for handling success and failure scenarios in C#.

NuGet License .NET

🚀 Introduction

TeymurDevv.ResultPattern is a simple yet powerful library that provides a structured way to handle operations that can either succeed or fail, reducing reliance on exceptions and improving code clarity.

✨ Features

  • Encapsulates success and failure outcomes in a single result type.
  • Eliminates excessive if-else checks.
  • Improves readability and maintainability of business logic.
  • Avoids using exceptions for expected errors.
  • Works seamlessly with ASP.NET Core, CQRS, and MediatR.

📦 Installation

Install via NuGet Package Manager:

Install-Package TeymurDevv.ResultPattern

Or via .NET CLI:

dotnet add package TeymurDevv.ResultPattern

🛠 Usage

1️⃣ Basic Success & Failure Handling

using TeymurDevv.ResultPattern;

var successResult = Result<string>.Success("Operation successful");
Console.WriteLine(successResult.Value); // Output: Operation successful

var failureResult = Result<string>.Failure("Something went wrong");
Console.WriteLine(failureResult.Error); // Output: Something went wrong

2️⃣ Using Result Without a Return Value

var operationResult = Result.Success();
if (operationResult.IsSuccess)
{
    Console.WriteLine("Operation succeeded");
}
else
{
    Console.WriteLine($"Error: {operationResult.Error}");
}

3️⃣ Using Result in a Service Layer

public class UserService
{
    public Result<User> GetUserById(int id)
    {
        var user = _userRepository.GetById(id);
        if (user == null)
        {
            return Result<User>.Failure("User not found");
        }
        return Result<User>.Success(user);
    }
}

4️⃣ Handling Result in an API Controller (ASP.NET Core)

[ApiController]
[Route("api/users")]
public class UserController : ControllerBase
{
    private readonly UserService _userService;

    public UserController(UserService userService)
    {
        _userService = userService;
    }

    [HttpGet("{id}")]
    public IActionResult GetUser(int id)
    {
        var result = _userService.GetUserById(id);
        
        if (result.IsFailure)
            return NotFound(new { message = result.Error });

        return Ok(result.Value);
    }
}

🔥 Why Use TeymurDevv.ResultPattern?

Explicit error handling – No more guessing where exceptions might occur.
Improves performance – Avoids costly exceptions for expected failures.
Increases maintainability – Cleaner and more structured error handling.
Works with CQRS & MediatR – Perfect for modern backend architectures.

⚡ Roadmap

  • Add logging integration
  • Extend support for Result<T> chaining
  • Improve compatibility with LINQ expressions

📜 License

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

🤝 Contributing

Contributions are welcome! Feel free to submit issues, feature requests, or pull requests on GitHub.

🌟 Support & Feedback

If you find this package useful, please ⭐ it on GitHub! 😊

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
1.0.0 125 2/25/2025