The Lunavex.Result
package is designed to encapsulate the result of operations in .NET applications, offering a structured way to handle success and failure states with associated data or error messages. It is ideal for improving error handling and response consistency across various application layers.
- Generic Result Type: Facilitates strong typing of the operation outcome, accommodating any data type.
- Error Handling: Enables capturing multiple error messages, suitable for scenarios requiring detailed feedback.
- HTTP Status Code Integration: Aligns operation results with HTTP response standards, enhancing API development.
- Implicit Conversions: Streamlines result creation from data or errors through implicit conversion operators.
To integrate Lunavex.Result
into your project, install it via the NuGet package manager:
Install-Package Lunavex.Result
Or through the .NET CLI:
dotnet add package Lunavex.Result
- For a successful operation, instantiate a Result object with the desired data:
var successResult = new Result<string>("Operation successful.");
- Alternatively, leverage implicit conversion from data:
Result<string> result = "Operation successful.";
- For failures, create a Result object with an HTTP status code and error messages:
var errorResult = new Result<string>(400, new List<string> { "Error 1", "Error 2" });
- Or use implicit conversion from error details:
Result<string> result = (400, new List<string> { "Error 1", "Error 2" });
- For single error messages:
Result<string> result = (400, "Single error message");
- For success using Succeed method:
Result<string> result = Result<string>.Succeed("Is successful");
- For error using Failure method:
- One error message
Result<string> result = Result<string>.Failure(500,"Is fail!");
- Multiple error messages
Result<string> result = Result<string>.Failure(500,new List<string>() {"Is fail!","Is not unique!"});
- One error message return 500 status code
Result<string> result = Result<string>.Failure("Is fail!"); //return 500 status code
- Multiple error messages return 500 status code
Result<string> result = Result<string>.Failure(new List<string>() {"Is fail!","Is not unique!"}); //return 500 status code
We welcome contributions! Feel free to open an issue or submit a pull request on our GitHub repository for any suggestions or improvements.
Lunavex.Result
is licensed under the MIT License. See the LICENSE file in the source repository for full details.
This Markdown formatted README provides a comprehensive guide on how to use the `Lunavex.Result` package, suitable for your project's repository or documentation.