This is a result class for .NET
$ dotnet add package TS.ResultThe TS.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.
To integrate TS.Result into your project, install it via the NuGet package manager:
Install-Package TS.Result
Or through the .NET CLI:
dotnet add package TS.Result
var successResult = new Result<string>("Operation successful.");
Result<string> result = "Operation successful.";
var errorResult = new Result<string>(400, new List<string> { "Error 1", "Error 2" });
Result<string> result = (400, new List<string> { "Error 1", "Error 2" });
Result<string> result = (400, "Single error message");
Result<string> result = Result<string>.Succeed("Is successful");
Result<string> result = Result<string>.Failure(500,"Is fail!");
Result<string> result = Result<string>.Failure(500,new List<string>() {"Is fail!","Is not unique!"});
Result<string> result = Result<string>.Failure("Is fail!"); //return 500 status code
Result<string> result = Result<string>.Failure(new List<string>() {"Is fail!","Is not unique!"}); //return 500 status code
{
"data": {
"token": "eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9",
"refreshToken": "dbfa1ced-6ae1-4120-beea-4d0dbde492e3",
"refreshTokenExpires": "2024-05-20T03:51:44.4942877Z"
},
"errorMessages": null,
}
{
"data": null,
"errorMessages": [
"Username must be at least 3 characters"
]
}
We welcome contributions! Feel free to open an issue or submit a pull request on our GitHub repository for any suggestions or improvements.
TS.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 `TS.Result` package, suitable for your project's repository or documentation.