Last active
August 16, 2019 17:19
-
-
Save deepumi/3eaf7678c7815d8237ba1fb14cd37728 to your computer and use it in GitHub Desktop.
HttpStatus code enum -> int & string
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using static System.Net.HttpStatusCode; | |
internal static class Extensions | |
{ | |
internal static string AsString(this HttpStatusCode status) => status switch | |
{ | |
Continue => nameof(Continue), | |
SwitchingProtocols => nameof(SwitchingProtocols), | |
Processing => nameof(Processing), | |
EarlyHints => nameof(EarlyHints), | |
OK => nameof(OK), | |
Created => nameof(Created), | |
Accepted => nameof(Accepted), | |
NonAuthoritativeInformation => nameof(NonAuthoritativeInformation), | |
NoContent => nameof(NoContent), | |
ResetContent => nameof(ResetContent), | |
PartialContent => nameof(PartialContent), | |
MultiStatus => nameof(MultiStatus), | |
AlreadyReported => nameof(AlreadyReported), | |
IMUsed => nameof(IMUsed), | |
MultipleChoices => nameof(MultipleChoices), | |
Moved => nameof(Moved), | |
Redirect => nameof(Redirect), | |
SeeOther => nameof(SeeOther), | |
NotModified => nameof(NotModified), | |
UseProxy => nameof(UseProxy), | |
Unused => nameof(Unused), | |
TemporaryRedirect => nameof(TemporaryRedirect), | |
PermanentRedirect => nameof(PermanentRedirect), | |
BadRequest => nameof(BadRequest), | |
Unauthorized => nameof(Unauthorized), | |
PaymentRequired => nameof(PaymentRequired), | |
Forbidden => nameof(Forbidden), | |
NotFound => nameof(NotFound), | |
MethodNotAllowed => nameof(MethodNotAllowed), | |
NotAcceptable => nameof(NotAcceptable), | |
ProxyAuthenticationRequired => nameof(ProxyAuthenticationRequired), | |
RequestTimeout => nameof(RequestTimeout), | |
Conflict => nameof(Conflict), | |
Gone => nameof(Gone), | |
LengthRequired => nameof(LengthRequired), | |
PreconditionFailed => nameof(PreconditionFailed), | |
RequestEntityTooLarge => nameof(RequestEntityTooLarge), | |
RequestUriTooLong => nameof(RequestUriTooLong), | |
UnsupportedMediaType => nameof(UnsupportedMediaType), | |
RequestedRangeNotSatisfiable => nameof(RequestedRangeNotSatisfiable), | |
ExpectationFailed => nameof(ExpectationFailed), | |
MisdirectedRequest => nameof(MisdirectedRequest), | |
UnprocessableEntity => nameof(UnprocessableEntity), | |
Locked => nameof(Locked), | |
FailedDependency => nameof(FailedDependency), | |
UpgradeRequired => nameof(UpgradeRequired), | |
PreconditionRequired => nameof(PreconditionRequired), | |
TooManyRequests => nameof(TooManyRequests), | |
RequestHeaderFieldsTooLarge => nameof(RequestHeaderFieldsTooLarge), | |
UnavailableForLegalReasons => nameof(UnavailableForLegalReasons), | |
InternalServerError => nameof(InternalServerError), | |
NotImplemented => nameof(NotImplemented), | |
BadGateway => nameof(BadGateway), | |
ServiceUnavailable => nameof(ServiceUnavailable), | |
GatewayTimeout => nameof(GatewayTimeout), | |
HttpVersionNotSupported => nameof(HttpVersionNotSupported), | |
VariantAlsoNegotiates => nameof(VariantAlsoNegotiates), | |
InsufficientStorage => nameof(InsufficientStorage), | |
LoopDetected => nameof(LoopDetected), | |
NotExtended => nameof(NotExtended), | |
NetworkAuthenticationRequired => nameof(NetworkAuthenticationRequired), | |
_ => "Unknown" | |
}; | |
internal static int AsInt(this HttpStatusCode status) => status switch | |
{ | |
Continue => 100, | |
SwitchingProtocols => 101, | |
Processing => 102, | |
EarlyHints => 103, | |
OK => 200, | |
Created => 201, | |
Accepted => 202, | |
NonAuthoritativeInformation => 203, | |
NoContent => 204, | |
ResetContent => 205, | |
PartialContent => 206, | |
MultiStatus => 207, | |
AlreadyReported => 208, | |
IMUsed => 226, | |
MultipleChoices => 300, | |
Moved => 301, | |
Redirect => 302, | |
SeeOther => 303, | |
NotModified => 304, | |
UseProxy => 305, | |
Unused => 306, | |
TemporaryRedirect => 307, | |
PermanentRedirect => 308, | |
BadRequest => 400, | |
Unauthorized => 401, | |
PaymentRequired => 402, | |
Forbidden => 403, | |
NotFound => 404, | |
MethodNotAllowed => 405, | |
NotAcceptable => 406, | |
ProxyAuthenticationRequired => 407, | |
RequestTimeout => 408, | |
Conflict => 409, | |
Gone => 410, | |
LengthRequired => 411, | |
PreconditionFailed => 412, | |
RequestEntityTooLarge => 413, | |
RequestUriTooLong => 414, | |
UnsupportedMediaType => 415, | |
RequestedRangeNotSatisfiable => 416, | |
ExpectationFailed => 417, | |
MisdirectedRequest => 421, | |
UnprocessableEntity => 422, | |
Locked => 423, | |
FailedDependency => 424, | |
UpgradeRequired => 426, | |
PreconditionRequired => 428, | |
TooManyRequests => 429, | |
RequestHeaderFieldsTooLarge => 431, | |
UnavailableForLegalReasons => 451, | |
InternalServerError => 500, | |
NotImplemented => 501, | |
BadGateway => 502, | |
ServiceUnavailable => 503, | |
GatewayTimeout => 504, | |
HttpVersionNotSupported => 505, | |
VariantAlsoNegotiates => 506, | |
InsufficientStorage => 507, | |
LoopDetected => 508, | |
NotExtended => 510, | |
NetworkAuthenticationRequired => 511, | |
_ => default | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment