DevSource.Stack.Results
2.0.0
See the version list below for details.
dotnet add package DevSource.Stack.Results --version 2.0.0
NuGet\Install-Package DevSource.Stack.Results -Version 2.0.0
<PackageReference Include="DevSource.Stack.Results" Version="2.0.0" />
<PackageVersion Include="DevSource.Stack.Results" Version="2.0.0" />
<PackageReference Include="DevSource.Stack.Results" />
paket add DevSource.Stack.Results --version 2.0.0
#r "nuget: DevSource.Stack.Results, 2.0.0"
#:package DevSource.Stack.Results@2.0.0
#addin nuget:?package=DevSource.Stack.Results&version=2.0.0
#tool nuget:?package=DevSource.Stack.Results&version=2.0.0
DevSource.Stack.Results
DevSource.Stack.Results is a lightweight and robust C# library designed to simplify error handling and improve the readability of your code. It provides a standardized way to return and handle results from functions and methods, clearly distinguishing between successful and failed results.
Features
Easy-to-use Result and Result<T> types for encapsulating operation outcomes.
Supports conveying error details, including custom messages and error codes.
Enhances code readability and maintainability.
Standardized return of responses.
Supports statuses for:
- Informational Responses (100 - 199);
- Successful Responses (200 - 299);
- Redirect Messages (300 - 399);
- Client Error Responses (400 - 499);
- Server Error Responses (500 - 599);
Installation and usage
To integrate this library into your project:
1- Setup: Include the library files in your project directory by installing directly from the NuGet repository.
dotnet add package DevSource.Stack.Results
2- Initialization: Instantiate the Smooth.Result and integrate it with your project's flow. Ex.:
using DevSource.Stack.Results;
3- Usage: You can use it in several ways. Here is an example of very common usage:
public class User
{
public string Email { get; set; }
public string Password { get; set; }
public User(string email, string password)
{
Email = email;
Password = password;
}
public Result<User> Auth(string email, string password)
{
var user = //...Some method to fetch user information.
if (email != user.Email || password != user.Password)
return Result<User>.Failure(Error.Unauthorized);
return Result<User>.Ok(data: user);
}
}
Failure output
{
"IsSuccess":false,
"StatusCode":401,
"ErrorMessage":"Unauthorized: Authentication is required and has failed or has not been provided.",
"Data":null
}
OK output
{
"IsSuccess":true,
"StatusCode":null,
"ErrorMessage":"",
"Data":{
"Email":"<User email>",
"Password":"<User password>"
}
}
If the method does not need to return any object, you can use it like this:
public class User
{
public string Email { get; set; }
public string Password { get; set; }
public User(string email, string password)
{
Email = email;
Password = password;
}
public Result Auth(string email, string password)
{
var user = //...Some method to fetch user information.
if (email != user.Email || password != user.Password)
return Result.Failure(Error.Unauthorized);
return Result.Ok();
}
}
Failure output
{
"IsSuccess":false,
"StatusCode":401,
"ErrorMessage":"Unauthorized: Authentication is required and has failed or has not been provided."
}
OK output
{
"IsSuccess":true,
"StatusCode":null,
"ErrorMessage":""
}
Error Types and messages errors
- 400 - BadRequest - [Error Message]: "Your request could not be understood due to malformed syntax."
- 401 - Unauthorized - [Error Message]: "Authentication is required and has failed or has not been provided."
- 402 - PaymentRequired - [Error Message]: "Payment is required to access this resource."
- 403 - Forbidden - [Error Message]: "You do not have the necessary permissions to access this resource."
- 404 - NotFound - [Error Message]: "The requested resource could not be found."
- 405 - MethodNotAllowed - [Error Message]: "The method specified in the request is not allowed for the resource identified."
- 406 - NotAcceptable - [Error Message]: "The resource is capable of generating only content not acceptable according to the Accept headers sent in the request."
- 407 - ProxyAuthenticationRequired - [Error Message]: "You must authenticate with a proxy server before this request can be served."
- 408 - RequestTimeout - [Error Message]: "The server timed out waiting for the request."
- 409 - Conflict - Error Message: "The request could not be completed due to a conflict with the current state of the resource."
- 410 - Gone - [Error Message]: "The requested resource is no longer available at the server and no forwarding address is known."
- 411 - LengthRequired - [Error Message]: "The request did not specify the length of its content, which is required by the requested resource."
- 412 - PreconditionFailed - [Error Message]: "One or more preconditions given in the request header fields evaluated to false when tested on the server."
- 413 - PayloadTooLarge - [Error Message]: "The server is refusing to process a request because the request payload is larger than the server is willing or able to process."
- 414 - UriToLong - [Error Message]: "The URI provided was too long for the server to process."
- 415 - UnsupportedMediaType - [Error Message]: "The server is refusing to service the request because the entity of the request is in a format not supported by the requested resource for the requested method."
- 416 - RangeNotSatisfiable - [Error Message]: "The server cannot serve the requested ranges."
- 417 - ExpectationFailed - [Error Message]: "The server cannot meet the requirements of the Expect request-header field."
- 421 - MisdirectedRequest - [Error Message]: "The request was directed at a server that is not able to produce a response."
- 422 - UnprocessableContent - [Error Message]: "The server understands the content type of the request entity, but was unable to process the contained instructions."
- 423 - Locked - [Error Message]: "The resource that is being accessed is locked."
- 424 - FailedDependency - [Error Message]: "The request failed due to the failure of a previous request."
- 425 - TooEarly - [Error Message]: "The server is unwilling to risk processing a request that might be replayed."
- 426 - UpgradeRequired - [Error Message]: "The client should switch to a different protocol."
- 428 - PreconditionRequired - [Error Message]: "The server requires the request to be conditional."
- 429 - TooManyRequests - [Error Message]: "You have sent too many requests in a given amount of time."
- 431 - RequestHeaderFieldsTooLarge - [Error Message]: "The server is unwilling to process the request because its header fields are too large."
- 451 - UnavailableForLegalReasons - [Error Message]: "The requested resource is unavailable due to legal reasons."
- 500 - InternalServerError - [Error Message]: "The server encountered an unexpected condition that prevented it from fulfilling the request."
- 501 - NotImplemented - [Error Message]: "The server does not support the functionality required to fulfill the request."
- 502 - BadGateway - [Error Message]: "The server received an invalid response from the upstream server."
- 503 - ServiceUnavailable - [Error Message]: "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server."
- 504 - GatewayTimeout - [Error Message]: "The upstream server failed to send a request in the time allowed by the server."
- 505 - HttpVersionNotSupported - [Error Message]: "The server does not support the HTTP protocol version that was used in the request."
- 506 - VariantAlsoNegotiates - [Error Message]: "The server has an internal configuration error: the chosen variant resource is configured to engage in transparent content negotiation and is therefore not a suitable endpoint in the negotiation process."
- 507 - InsufficientStorage - [Error Message]: "The server is unable to store the representation needed to complete the request."
- 508 - LoopDetected - [Error Message]: "The server detected an infinite loop while processing the request."
- 510 - NotExtended - [Error Message]: "Further extensions to the request are required for the server to fulfill it."
- 511 - NetworkAuthenticationRequired - [Error Message]: "The client needs to authenticate to gain network access."
Running the tests
To run the tests, run the following command
dotnet test
Contributing
Contributions are what make the open source community such an amazing place to learn, be inspired, and create. Any contributions you make will be greatly appreciated.
Fork the Project
- Create your Feature Branch (git checkout -b feat/contributing)
- Commit your changes (git commit -m 'Add some contribute')
- Push to the Branch (git push origin feat/contributing)
- Open a Pull Request
Support and Contact
If you encounter any issues or have questions, please feel free to reach out through our GitHub Issues page.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. 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. |
-
net8.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.