TeymurDevv.ResultPattern
1.0.0
dotnet add package TeymurDevv.ResultPattern --version 1.0.0
NuGet\Install-Package TeymurDevv.ResultPattern -Version 1.0.0
<PackageReference Include="TeymurDevv.ResultPattern" Version="1.0.0" />
<PackageVersion Include="TeymurDevv.ResultPattern" Version="1.0.0" />
<PackageReference Include="TeymurDevv.ResultPattern" />
paket add TeymurDevv.ResultPattern --version 1.0.0
#r "nuget: TeymurDevv.ResultPattern, 1.0.0"
#:package TeymurDevv.ResultPattern@1.0.0
#addin nuget:?package=TeymurDevv.ResultPattern&version=1.0.0
#tool nuget:?package=TeymurDevv.ResultPattern&version=1.0.0
TeymurDevv.ResultPattern
A lightweight and elegant Result Pattern implementation for handling success and failure scenarios in C#.
🚀 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 | 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
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 |