(bugfix): resolve the ambiguous calls 2

This commit is contained in:
Maksym Sadovnychyy 2024-09-28 17:41:06 +02:00
parent f84d7fc12e
commit ba41e44741
6 changed files with 193 additions and 865 deletions

View File

@ -8,7 +8,7 @@
<!-- NuGet package metadata --> <!-- NuGet package metadata -->
<PackageId>MaksIT.Results</PackageId> <PackageId>MaksIT.Results</PackageId>
<Version>1.0.4</Version> <Version>1.0.5</Version>
<Authors>Maksym Sadovnychyy</Authors> <Authors>Maksym Sadovnychyy</Authors>
<Company>MAKS-IT</Company> <Company>MAKS-IT</Company>
<Product>MaksIT.Results</Product> <Product>MaksIT.Results</Product>

View File

@ -9,225 +9,120 @@ public partial class Result {
/// Returns a result indicating that the server could not understand the request due to invalid syntax. /// Returns a result indicating that the server could not understand the request due to invalid syntax.
/// Corresponds to HTTP status code 400 Bad Request. /// Corresponds to HTTP status code 400 Bad Request.
/// </summary> /// </summary>
public static Result BadRequest(string message) => public static Result BadRequest(params string [] messages) {
BadRequest(new List<string> { message }); return new Result(false, [..messages], HttpStatusCode.BadRequest);
/// <summary>
/// Returns a result indicating that the server could not understand the request due to invalid syntax.
/// Corresponds to HTTP status code 400 Bad Request.
/// </summary>
public static Result BadRequest(List<string> messages) {
return new Result(false, messages, HttpStatusCode.BadRequest);
} }
/// <summary> /// <summary>
/// Returns a result indicating that the client must authenticate itself to get the requested response. /// Returns a result indicating that the client must authenticate itself to get the requested response.
/// Corresponds to HTTP status code 401 Unauthorized. /// Corresponds to HTTP status code 401 Unauthorized.
/// </summary> /// </summary>
public static Result Unauthorized(string message) => public static Result Unauthorized(params string [] messages) {
Unauthorized(new List<string> { message }); return new Result(false, [..messages], HttpStatusCode.Unauthorized);
/// <summary>
/// Returns a result indicating that the client must authenticate itself to get the requested response.
/// Corresponds to HTTP status code 401 Unauthorized.
/// </summary>
public static Result Unauthorized(List<string> messages) {
return new Result(false, messages, HttpStatusCode.Unauthorized);
} }
/// <summary> /// <summary>
/// Returns a result indicating that the client does not have access rights to the content. /// Returns a result indicating that the client does not have access rights to the content.
/// Corresponds to HTTP status code 403 Forbidden. /// Corresponds to HTTP status code 403 Forbidden.
/// </summary> /// </summary>
public static Result Forbidden(string message) => public static Result Forbidden(params string [] messages) {
Forbidden(new List<string> { message }); return new Result(false, [..messages], HttpStatusCode.Forbidden);
/// <summary>
/// Returns a result indicating that the client does not have access rights to the content.
/// Corresponds to HTTP status code 403 Forbidden.
/// </summary>
public static Result Forbidden(List<string> messages) {
return new Result(false, messages, HttpStatusCode.Forbidden);
} }
/// <summary> /// <summary>
/// Returns a result indicating that the server can not find the requested resource. /// Returns a result indicating that the server can not find the requested resource.
/// Corresponds to HTTP status code 404 Not Found. /// Corresponds to HTTP status code 404 Not Found.
/// </summary> /// </summary>
public static Result NotFound(string message) => public static Result NotFound(params string [] messages) {
NotFound(new List<string> { message }); return new Result(false, [.. messages], HttpStatusCode.NotFound);
/// <summary>
/// Returns a result indicating that the server can not find the requested resource.
/// Corresponds to HTTP status code 404 Not Found.
/// </summary>
public static Result NotFound(List<string> messagess) {
return new Result(false, messagess, HttpStatusCode.NotFound);
} }
/// <summary> /// <summary>
/// Returns a result indicating that the request could not be completed due to a conflict with the current state of the resource. /// Returns a result indicating that the request could not be completed due to a conflict with the current state of the resource.
/// Corresponds to HTTP status code 409 Conflict. /// Corresponds to HTTP status code 409 Conflict.
/// </summary> /// </summary>
public static Result Conflict(string message) => public static Result Conflict(params string [] messages) {
Conflict(new List<string> { message }); return new Result(false, [..messages], HttpStatusCode.Conflict);
/// <summary>
/// Returns a result indicating that the request could not be completed due to a conflict with the current state of the resource.
/// Corresponds to HTTP status code 409 Conflict.
/// </summary>
public static Result Conflict(List<string> messages) {
return new Result(false, messages, HttpStatusCode.Conflict);
} }
/// <summary> /// <summary>
/// Returns a result indicating that the requested resource is no longer available and will not be available again. /// Returns a result indicating that the requested resource is no longer available and will not be available again.
/// Corresponds to HTTP status code 410 Gone. /// Corresponds to HTTP status code 410 Gone.
/// </summary> /// </summary>
public static Result Gone(string message) => public static Result Gone(params string [] messages) {
Gone(new List<string> { message }); return new Result(false, [..messages], (HttpStatusCode)410); // 410 Gone
/// <summary>
/// Returns a result indicating that the requested resource is no longer available and will not be available again.
/// Corresponds to HTTP status code 410 Gone.
/// </summary>
public static Result Gone(List<string> messages) {
return new Result(false, messages, (HttpStatusCode)410); // 410 Gone
} }
/// <summary> /// <summary>
/// Returns a result indicating that the request failed because it depended on another request and that request failed. /// Returns a result indicating that the request failed because it depended on another request and that request failed.
/// Corresponds to HTTP status code 424 Failed Dependency. /// Corresponds to HTTP status code 424 Failed Dependency.
/// </summary> /// </summary>
public static Result FailedDependency(string message) => public static Result FailedDependency(params string [] messages) {
FailedDependency(new List<string> { message }); return new Result(false, [..messages], (HttpStatusCode)424); // 424 Failed Dependency
/// <summary>
/// Returns a result indicating that the request failed because it depended on another request and that request failed.
/// Corresponds to HTTP status code 424 Failed Dependency.
/// </summary>
public static Result FailedDependency(List<string> messages) {
return new Result(false, messages, (HttpStatusCode)424); // 424 Failed Dependency
} }
/// <summary> /// <summary>
/// Returns a result indicating that the server requires the request to be conditional. /// Returns a result indicating that the server requires the request to be conditional.
/// Corresponds to HTTP status code 428 Precondition Required. /// Corresponds to HTTP status code 428 Precondition Required.
/// </summary> /// </summary>
public static Result PreconditionRequired(string message) => public static Result PreconditionRequired(params string [] messages) {
PreconditionRequired(new List<string> { message }); return new Result(false, [..messages], (HttpStatusCode)428); // 428 Precondition Required
/// <summary>
/// Returns a result indicating that the server requires the request to be conditional.
/// Corresponds to HTTP status code 428 Precondition Required.
/// </summary>
public static Result PreconditionRequired(List<string> messages) {
return new Result(false, messages, (HttpStatusCode)428); // 428 Precondition Required
} }
/// <summary> /// <summary>
/// Returns a result indicating that the user has sent too many requests in a given amount of time. /// Returns a result indicating that the user has sent too many requests in a given amount of time.
/// Corresponds to HTTP status code 429 Too Many Requests. /// Corresponds to HTTP status code 429 Too Many Requests.
/// </summary> /// </summary>
public static Result TooManyRequests(string message) => public static Result TooManyRequests(params string [] messages) {
TooManyRequests(new List<string> { message }); return new Result(false, [..messages], (HttpStatusCode)429); // 429 Too Many Requests
/// <summary>
/// Returns a result indicating that the user has sent too many requests in a given amount of time.
/// Corresponds to HTTP status code 429 Too Many Requests.
/// </summary>
public static Result TooManyRequests(List<string> messages) {
return new Result(false, messages, (HttpStatusCode)429); // 429 Too Many Requests
} }
/// <summary> /// <summary>
/// Returns a result indicating that the server is unwilling to process the request because its header fields are too large. /// Returns a result indicating that the server is unwilling to process the request because its header fields are too large.
/// Corresponds to HTTP status code 431 Request Header Fields Too Large. /// Corresponds to HTTP status code 431 Request Header Fields Too Large.
/// </summary> /// </summary>
public static Result RequestHeaderFieldsTooLarge(string message) => public static Result RequestHeaderFieldsTooLarge(params string [] messages) {
RequestHeaderFieldsTooLarge(new List<string> { message }); return new Result(false, [..messages], (HttpStatusCode)431); // 431 Request Header Fields Too Large
/// <summary>
/// Returns a result indicating that the server is unwilling to process the request because its header fields are too large.
/// Corresponds to HTTP status code 431 Request Header Fields Too Large.
/// </summary>
public static Result RequestHeaderFieldsTooLarge(List<string> messages) {
return new Result(false, messages, (HttpStatusCode)431); // 431 Request Header Fields Too Large
} }
/// <summary> /// <summary>
/// Returns a result indicating that the server cannot process the request entity because it is too large. /// Returns a result indicating that the server cannot process the request entity because it is too large.
/// Corresponds to HTTP status code 413 Payload Too Large. /// Corresponds to HTTP status code 413 Payload Too Large.
/// </summary> /// </summary>
public static Result PayloadTooLarge(string message) => public static Result PayloadTooLarge(params string [] messages) {
PayloadTooLarge(new List<string> { message }); return new Result(false, [..messages], (HttpStatusCode)413); // 413 Payload Too Large
/// <summary>
/// Returns a result indicating that the server cannot process the request entity because it is too large.
/// Corresponds to HTTP status code 413 Payload Too Large.
/// </summary>
public static Result PayloadTooLarge(List<string> messages) {
return new Result(false, messages, (HttpStatusCode)413); // 413 Payload Too Large
} }
/// <summary> /// <summary>
/// Returns a result indicating that the server cannot process the request because the URI is too long. /// Returns a result indicating that the server cannot process the request because the URI is too long.
/// Corresponds to HTTP status code 414 URI Too Long. /// Corresponds to HTTP status code 414 URI Too Long.
/// </summary> /// </summary>
public static Result UriTooLong(string message) => public static Result UriTooLong(params string [] messages) {
UriTooLong(new List<string> { message }); return new Result(false, [..messages], (HttpStatusCode)414); // 414 URI Too Long
/// <summary>
/// Returns a result indicating that the server cannot process the request because the URI is too long.
/// Corresponds to HTTP status code 414 URI Too Long.
/// </summary>
public static Result UriTooLong(List<string> messages) {
return new Result(false, messages, (HttpStatusCode)414); // 414 URI Too Long
} }
/// <summary> /// <summary>
/// Returns a result indicating that the server cannot process the request because the media type is unsupported. /// Returns a result indicating that the server cannot process the request because the media type is unsupported.
/// Corresponds to HTTP status code 415 Unsupported Media Type. /// Corresponds to HTTP status code 415 Unsupported Media Type.
/// </summary> /// </summary>
public static Result UnsupportedMediaType(string message) => public static Result UnsupportedMediaType(params string [] messages) {
UnsupportedMediaType(new List<string> { message }); return new Result(false, [..messages], HttpStatusCode.UnsupportedMediaType);
/// <summary>
/// Returns a result indicating that the server cannot process the request because the media type is unsupported.
/// Corresponds to HTTP status code 415 Unsupported Media Type.
/// </summary>
public static Result UnsupportedMediaType(List<string> messages) {
return new Result(false, messages, HttpStatusCode.UnsupportedMediaType);
} }
/// <summary> /// <summary>
/// Returns a result indicating that the server cannot process the request because it expects the request to have a defined Content-Length header. /// Returns a result indicating that the server cannot process the request because it expects the request to have a defined Content-Length header.
/// Corresponds to HTTP status code 411 Length Required. /// Corresponds to HTTP status code 411 Length Required.
/// </summary> /// </summary>
public static Result LengthRequired(string message) => public static Result LengthRequired(params string [] messages) {
LengthRequired(new List<string> { message }); return new Result(false, [..messages], (HttpStatusCode)411); // 411 Length Required
/// <summary>
/// Returns a result indicating that the server cannot process the request because it expects the request to have a defined Content-Length header.
/// Corresponds to HTTP status code 411 Length Required.
/// </summary>
public static Result LengthRequired(List<string> messages) {
return new Result(false, messages, (HttpStatusCode)411); // 411 Length Required
} }
/// <summary> /// <summary>
/// Returns a result indicating that the server cannot process the request due to an illegal request entity. /// Returns a result indicating that the server cannot process the request due to an illegal request entity.
/// Corresponds to HTTP status code 422 Unprocessable Entity. /// Corresponds to HTTP status code 422 Unprocessable Entity.
/// </summary> /// </summary>
public static Result UnprocessableEntity(string message) => public static Result UnprocessableEntity(params string [] messages) {
UnprocessableEntity(new List<string> { message }); return new Result(false, [..messages], (HttpStatusCode)422); // 422 Unprocessable Entity
/// <summary>
/// Returns a result indicating that the server cannot process the request due to an illegal request entity.
/// Corresponds to HTTP status code 422 Unprocessable Entity.
/// </summary>
public static Result UnprocessableEntity(List<string> messages) {
return new Result(false, messages, (HttpStatusCode)422); // 422 Unprocessable Entity
} }
} }
@ -237,224 +132,119 @@ public partial class Result<T> : Result {
/// Returns a result indicating that the server could not understand the request due to invalid syntax. /// Returns a result indicating that the server could not understand the request due to invalid syntax.
/// Corresponds to HTTP status code 400 Bad Request. /// Corresponds to HTTP status code 400 Bad Request.
/// </summary> /// </summary>
public static Result<T> BadRequest(T? value, string message) => public static Result<T> BadRequest(T? value, params string [] messages) {
BadRequest(value, new List<string> { message }); return new Result<T>(value, false, [..messages], HttpStatusCode.BadRequest);
/// <summary>
/// Returns a result indicating that the server could not understand the request due to invalid syntax.
/// Corresponds to HTTP status code 400 Bad Request.
/// </summary>
public static Result<T> BadRequest(T? value, List<string> messages) {
return new Result<T>(value, false, messages, HttpStatusCode.BadRequest);
} }
/// <summary> /// <summary>
/// Returns a result indicating that the client must authenticate itself to get the requested response. /// Returns a result indicating that the client must authenticate itself to get the requested response.
/// Corresponds to HTTP status code 401 Unauthorized. /// Corresponds to HTTP status code 401 Unauthorized.
/// </summary> /// </summary>
public static Result<T> Unauthorized(T? value, string message) => public static Result<T> Unauthorized(T? value, params string [] messages) {
Unauthorized(value, new List<string> { message }); return new Result<T>(value, false, [..messages], HttpStatusCode.Unauthorized);
/// <summary>
/// Returns a result indicating that the client must authenticate itself to get the requested response.
/// Corresponds to HTTP status code 401 Unauthorized.
/// </summary>
public static Result<T> Unauthorized(T? value, List<string> messages) {
return new Result<T>(value, false, messages, HttpStatusCode.Unauthorized);
} }
/// <summary> /// <summary>
/// Returns a result indicating that the client does not have access rights to the content. /// Returns a result indicating that the client does not have access rights to the content.
/// Corresponds to HTTP status code 403 Forbidden. /// Corresponds to HTTP status code 403 Forbidden.
/// </summary> /// </summary>
public static Result<T> Forbidden(T? value, string message) => public static Result<T> Forbidden(T? value, params string [] messages) {
Forbidden(value, new List<string> { message }); return new Result<T>(value, false, [..messages], HttpStatusCode.Forbidden);
/// <summary>
/// Returns a result indicating that the client does not have access rights to the content.
/// Corresponds to HTTP status code 403 Forbidden.
/// </summary>
public static Result<T> Forbidden(T? value, List<string> messages) {
return new Result<T>(value, false, messages, HttpStatusCode.Forbidden);
} }
/// <summary> /// <summary>
/// Returns a result indicating that the server can not find the requested resource. /// Returns a result indicating that the server can not find the requested resource.
/// Corresponds to HTTP status code 404 Not Found. /// Corresponds to HTTP status code 404 Not Found.
/// </summary> /// </summary>
public static Result<T> NotFound(T? value, string message) => public static Result<T> NotFound(T? value, params string [] messages) {
NotFound(value, new List<string> { message }); return new Result<T>(value, false, [..messages], HttpStatusCode.NotFound);
/// <summary>
/// Returns a result indicating that the server can not find the requested resource.
/// Corresponds to HTTP status code 404 Not Found.
/// </summary>
public static Result<T> NotFound(T? value, List<string> messages) {
return new Result<T>(value, false, messages, HttpStatusCode.NotFound);
} }
/// <summary> /// <summary>
/// Returns a result indicating that the request could not be completed due to a conflict with the current state of the resource. /// Returns a result indicating that the request could not be completed due to a conflict with the current state of the resource.
/// Corresponds to HTTP status code 409 Conflict. /// Corresponds to HTTP status code 409 Conflict.
/// </summary> /// </summary>
public static Result<T> Conflict(T? value, string message) => public static Result<T> Conflict(T? value, params string [] messages) {
Conflict(value, new List<string> { message }); return new Result<T>(value, false, [..messages], HttpStatusCode.Conflict);
/// <summary>
/// Returns a result indicating that the request could not be completed due to a conflict with the current state of the resource.
/// Corresponds to HTTP status code 409 Conflict.
/// </summary>
public static Result<T> Conflict(T? value, List<string> messages) {
return new Result<T>(value, false, messages, HttpStatusCode.Conflict);
} }
/// <summary> /// <summary>
/// Returns a result indicating that the requested resource is no longer available and will not be available again. /// Returns a result indicating that the requested resource is no longer available and will not be available again.
/// Corresponds to HTTP status code 410 Gone. /// Corresponds to HTTP status code 410 Gone.
/// </summary> /// </summary>
public static Result<T> Gone(T? value, string message) => public static Result<T> Gone(T? value, params string [] messages) {
Gone(value, new List<string> { message }); return new Result<T>(value, false, [..messages], (HttpStatusCode)410); // 410 Gone
/// <summary>
/// Returns a result indicating that the requested resource is no longer available and will not be available again.
/// Corresponds to HTTP status code 410 Gone.
/// </summary>
public static Result<T> Gone(T? value, List<string> messages) {
return new Result<T>(value, false, messages, (HttpStatusCode)410); // 410 Gone
} }
/// <summary> /// <summary>
/// Returns a result indicating that the request failed because it depended on another request and that request failed. /// Returns a result indicating that the request failed because it depended on another request and that request failed.
/// Corresponds to HTTP status code 424 Failed Dependency. /// Corresponds to HTTP status code 424 Failed Dependency.
/// </summary> /// </summary>
public static Result<T> FailedDependency(T? value, string message) => public static Result<T> FailedDependency(T? value, params string [] messages) {
FailedDependency(value, new List<string> { message }); return new Result<T>(value, false, [..messages], (HttpStatusCode)424); // 424 Failed Dependency
/// <summary>
/// Returns a result indicating that the request failed because it depended on another request and that request failed.
/// Corresponds to HTTP status code 424 Failed Dependency.
/// </summary>
public static Result<T> FailedDependency(T? value, List<string> messages) {
return new Result<T>(value, false, messages, (HttpStatusCode)424); // 424 Failed Dependency
} }
/// <summary> /// <summary>
/// Returns a result indicating that the server requires the request to be conditional. /// Returns a result indicating that the server requires the request to be conditional.
/// Corresponds to HTTP status code 428 Precondition Required. /// Corresponds to HTTP status code 428 Precondition Required.
/// </summary> /// </summary>
public static Result<T> PreconditionRequired(T? value, string message) => public static Result<T> PreconditionRequired(T? value, params string [] messages) {
PreconditionRequired(value, new List<string> { message }); return new Result<T>(value, false, [..messages], (HttpStatusCode)428); // 428 Precondition Required
/// <summary>
/// Returns a result indicating that the server requires the request to be conditional.
/// Corresponds to HTTP status code 428 Precondition Required.
/// </summary>
public static Result<T> PreconditionRequired(T? value, List<string> messages) {
return new Result<T>(value, false, messages, (HttpStatusCode)428); // 428 Precondition Required
} }
/// <summary> /// <summary>
/// Returns a result indicating that the user has sent too many requests in a given amount of time. /// Returns a result indicating that the user has sent too many requests in a given amount of time.
/// Corresponds to HTTP status code 429 Too Many Requests. /// Corresponds to HTTP status code 429 Too Many Requests.
/// </summary> /// </summary>
public static Result<T> TooManyRequests(T? value, string message) => public static Result<T> TooManyRequests(T? value, params string [] messages) {
TooManyRequests(value, new List<string> { message }); return new Result<T>(value, false, [..messages], (HttpStatusCode)429); // 429 Too Many Requests
/// <summary>
/// Returns a result indicating that the user has sent too many requests in a given amount of time.
/// Corresponds to HTTP status code 429 Too Many Requests.
/// </summary>
public static Result<T> TooManyRequests(T? value, List<string> messages) {
return new Result<T>(value, false, messages, (HttpStatusCode)429); // 429 Too Many Requests
} }
/// <summary> /// <summary>
/// Returns a result indicating that the server is unwilling to process the request because its header fields are too large. /// Returns a result indicating that the server is unwilling to process the request because its header fields are too large.
/// Corresponds to HTTP status code 431 Request Header Fields Too Large. /// Corresponds to HTTP status code 431 Request Header Fields Too Large.
/// </summary> /// </summary>
public static Result<T> RequestHeaderFieldsTooLarge(T? value, string message) => public static Result<T> RequestHeaderFieldsTooLarge(T? value, params string [] messages) {
RequestHeaderFieldsTooLarge(value, new List<string> { message }); return new Result<T>(value, false, [..messages], (HttpStatusCode)431); // 431 Request Header Fields Too Large
/// <summary>
/// Returns a result indicating that the server is unwilling to process the request because its header fields are too large.
/// Corresponds to HTTP status code 431 Request Header Fields Too Large.
/// </summary>
public static Result<T> RequestHeaderFieldsTooLarge(T? value, List<string> messages) {
return new Result<T>(value, false, messages, (HttpStatusCode)431); // 431 Request Header Fields Too Large
} }
/// <summary> /// <summary>
/// Returns a result indicating that the server cannot process the request entity because it is too large. /// Returns a result indicating that the server cannot process the request entity because it is too large.
/// Corresponds to HTTP status code 413 Payload Too Large. /// Corresponds to HTTP status code 413 Payload Too Large.
/// </summary> /// </summary>
public static Result<T> PayloadTooLarge(T? value, string message) => public static Result<T> PayloadTooLarge(T? value, params string [] messages) {
PayloadTooLarge(value, new List<string> { message }); return new Result<T>(value, false, [..messages], (HttpStatusCode)413); // 413 Payload Too Large
/// <summary>
/// Returns a result indicating that the server cannot process the request entity because it is too large.
/// Corresponds to HTTP status code 413 Payload Too Large.
/// </summary>
public static Result<T> PayloadTooLarge(T? value, List<string> messages) {
return new Result<T>(value, false, messages, (HttpStatusCode)413); // 413 Payload Too Large
} }
/// <summary> /// <summary>
/// Returns a result indicating that the server cannot process the request because the URI is too long. /// Returns a result indicating that the server cannot process the request because the URI is too long.
/// Corresponds to HTTP status code 414 URI Too Long. /// Corresponds to HTTP status code 414 URI Too Long.
/// </summary> /// </summary>
public static Result<T> UriTooLong(T? value, string message) => public static Result<T> UriTooLong(T? value, params string [] messages) {
UriTooLong(value, new List<string> { message }); return new Result<T>(value, false, [..messages], (HttpStatusCode)414); // 414 URI Too Long
/// <summary>
/// Returns a result indicating that the server cannot process the request because the URI is too long.
/// Corresponds to HTTP status code 414 URI Too Long.
/// </summary>
public static Result<T> UriTooLong(T? value, List<string> messages) {
return new Result<T>(value, false, messages, (HttpStatusCode)414); // 414 URI Too Long
} }
/// <summary> /// <summary>
/// Returns a result indicating that the server cannot process the request because the media type is unsupported. /// Returns a result indicating that the server cannot process the request because the media type is unsupported.
/// Corresponds to HTTP status code 415 Unsupported Media Type. /// Corresponds to HTTP status code 415 Unsupported Media Type.
/// </summary> /// </summary>
public static Result<T> UnsupportedMediaType(T? value, string message) => public static Result<T> UnsupportedMediaType(T? value, params string [] messages) {
UnsupportedMediaType(value, new List<string> { message }); return new Result<T>(value, false, [..messages], HttpStatusCode.UnsupportedMediaType);
/// <summary>
/// Returns a result indicating that the server cannot process the request because the media type is unsupported.
/// Corresponds to HTTP status code 415 Unsupported Media Type.
/// </summary>
public static Result<T> UnsupportedMediaType(T? value, List<string> messages) {
return new Result<T>(value, false, messages, HttpStatusCode.UnsupportedMediaType);
} }
/// <summary> /// <summary>
/// Returns a result indicating that the server cannot process the request because it expects the request to have a defined Content-Length header. /// Returns a result indicating that the server cannot process the request because it expects the request to have a defined Content-Length header.
/// Corresponds to HTTP status code 411 Length Required. /// Corresponds to HTTP status code 411 Length Required.
/// </summary> /// </summary>
public static Result<T> LengthRequired(T? value, string message) => public static Result<T> LengthRequired(T? value, params string [] messages) {
LengthRequired(value, new List<string> { message }); return new Result<T>(value, false, [..messages], (HttpStatusCode)411); // 411 Length Required
/// <summary>
/// Returns a result indicating that the server cannot process the request because it expects the request to have a defined Content-Length header.
/// Corresponds to HTTP status code 411 Length Required.
/// </summary>
public static Result<T> LengthRequired(T? value, List<string> messages) {
return new Result<T>(value, false, messages, (HttpStatusCode)411); // 411 Length Required
} }
/// <summary> /// <summary>
/// Returns a result indicating that the server cannot process the request due to an illegal request entity. /// Returns a result indicating that the server cannot process the request due to an illegal request entity.
/// Corresponds to HTTP status code 422 Unprocessable Entity. /// Corresponds to HTTP status code 422 Unprocessable Entity.
/// </summary> /// </summary>
public static Result<T> UnprocessableEntity(T? value, string message) => public static Result<T> UnprocessableEntity(T? value, params string [] messages) {
UnprocessableEntity(value, new List<string> { message }); return new Result<T>(value, false, [..messages], (HttpStatusCode)422); // 422 Unprocessable Entity
/// <summary>
/// Returns a result indicating that the server cannot process the request due to an illegal request entity.
/// Corresponds to HTTP status code 422 Unprocessable Entity.
/// </summary>
public static Result<T> UnprocessableEntity(T? value, List<string> messages) {
return new Result<T>(value, false, messages, (HttpStatusCode)422); // 422 Unprocessable Entity
} }
} }

View File

@ -9,60 +9,32 @@ public partial class Result {
/// Returns a result indicating that the initial part of a request has been received and the client should continue with the request. /// Returns a result indicating that the initial part of a request has been received and the client should continue with the request.
/// Corresponds to HTTP status code 100 Continue. /// Corresponds to HTTP status code 100 Continue.
/// </summary> /// </summary>
public static Result Continue(string message) => public static Result Continue(params string [] messages) {
Continue(new List<string> { message }); return new Result(true, [..messages], HttpStatusCode.Continue);
/// <summary>
/// Returns a result indicating that the initial part of a request has been received and the client should continue with the request.
/// Corresponds to HTTP status code 100 Continue.
/// </summary>
public static Result Continue(List<string> messages) {
return new Result(true, messages, HttpStatusCode.Continue);
} }
/// <summary> /// <summary>
/// Returns a result indicating that the server is switching to a different protocol as requested by the client. /// Returns a result indicating that the server is switching to a different protocol as requested by the client.
/// Corresponds to HTTP status code 101 Switching Protocols. /// Corresponds to HTTP status code 101 Switching Protocols.
/// </summary> /// </summary>
public static Result SwitchingProtocols(string message) => public static Result SwitchingProtocols(params string [] messages) {
SwitchingProtocols(new List<string> { message }); return new Result(true, [..messages], HttpStatusCode.SwitchingProtocols);
/// <summary>
/// Returns a result indicating that the server is switching to a different protocol as requested by the client.
/// Corresponds to HTTP status code 101 Switching Protocols.
/// </summary>
public static Result SwitchingProtocols(List<string> messages) {
return new Result(true, messages, HttpStatusCode.SwitchingProtocols);
} }
/// <summary> /// <summary>
/// Returns a result indicating that the server has received and is processing the request, but no response is available yet. /// Returns a result indicating that the server has received and is processing the request, but no response is available yet.
/// Corresponds to HTTP status code 102 Processing. /// Corresponds to HTTP status code 102 Processing.
/// </summary> /// </summary>
public static Result Processing(string message) => public static Result Processing(params string [] messages) {
Processing(new List<string> { message }); return new Result(true, [..messages], HttpStatusCode.Processing);
/// <summary>
/// Returns a result indicating that the server has received and is processing the request, but no response is available yet.
/// Corresponds to HTTP status code 102 Processing.
/// </summary>
public static Result Processing(List<string> messages) {
return new Result(true, messages, HttpStatusCode.Processing);
} }
/// <summary> /// <summary>
/// Returns a result indicating that the server is sending information about early hints that may be used by the client to begin preloading resources while the server prepares a final response. /// Returns a result indicating that the server is sending information about early hints that may be used by the client to begin preloading resources while the server prepares a final response.
/// Corresponds to HTTP status code 103 Early Hints. /// Corresponds to HTTP status code 103 Early Hints.
/// </summary> /// </summary>
public static Result EarlyHints(string message) => public static Result EarlyHints(params string [] messages) {
EarlyHints(new List<string> { message }); return new Result(true, [..messages], (HttpStatusCode)103); // Early Hints is not defined in HttpStatusCode enum, 103 is the official code
/// <summary>
/// Returns a result indicating that the server is sending information about early hints that may be used by the client to begin preloading resources while the server prepares a final response.
/// Corresponds to HTTP status code 103 Early Hints.
/// </summary>
public static Result EarlyHints(List<string> messages) {
return new Result(true, messages, (HttpStatusCode)103); // Early Hints is not defined in HttpStatusCode enum, 103 is the official code
} }
} }
@ -72,60 +44,32 @@ public partial class Result<T> : Result {
/// Returns a result indicating that the initial part of a request has been received and the client should continue with the request. /// Returns a result indicating that the initial part of a request has been received and the client should continue with the request.
/// Corresponds to HTTP status code 100 Continue. /// Corresponds to HTTP status code 100 Continue.
/// </summary> /// </summary>
public static Result<T> Continue(T? value, string message) => public static Result<T> Continue(T? value, params string [] messages) {
Continue(value, new List<string> { message }); return new Result<T>(value, true, [..messages], HttpStatusCode.Continue);
/// <summary>
/// Returns a result indicating that the initial part of a request has been received and the client should continue with the request.
/// Corresponds to HTTP status code 100 Continue.
/// </summary>
public static Result<T> Continue(T? value, List<string> messages) {
return new Result<T>(value, true, messages, HttpStatusCode.Continue);
} }
/// <summary> /// <summary>
/// Returns a result indicating that the server is switching to a different protocol as requested by the client. /// Returns a result indicating that the server is switching to a different protocol as requested by the client.
/// Corresponds to HTTP status code 101 Switching Protocols. /// Corresponds to HTTP status code 101 Switching Protocols.
/// </summary> /// </summary>
public static Result<T> SwitchingProtocols(T? value, string message) => public static Result<T> SwitchingProtocols(T? value, params string [] messages) {
SwitchingProtocols(value, new List<string> { message }); return new Result<T>(value, true, [..messages], HttpStatusCode.SwitchingProtocols);
/// <summary>
/// Returns a result indicating that the server is switching to a different protocol as requested by the client.
/// Corresponds to HTTP status code 101 Switching Protocols.
/// </summary>
public static Result<T> SwitchingProtocols(T? value, List<string> messages) {
return new Result<T>(value, true, messages, HttpStatusCode.SwitchingProtocols);
} }
/// <summary> /// <summary>
/// Returns a result indicating that the server has received and is processing the request, but no response is available yet. /// Returns a result indicating that the server has received and is processing the request, but no response is available yet.
/// Corresponds to HTTP status code 102 Processing. /// Corresponds to HTTP status code 102 Processing.
/// </summary> /// </summary>
public static Result<T> Processing(T? value, string message) => public static Result<T> Processing(T? value, params string [] messages) {
Processing(value, new List<string> { message }); return new Result<T>(value, true, [..messages], HttpStatusCode.Processing);
/// <summary>
/// Returns a result indicating that the server has received and is processing the request, but no response is available yet.
/// Corresponds to HTTP status code 102 Processing.
/// </summary>
public static Result<T> Processing(T? value, List<string> messages) {
return new Result<T>(value, true, messages, HttpStatusCode.Processing);
} }
/// <summary> /// <summary>
/// Returns a result indicating that the server is sending information about early hints that may be used by the client to begin preloading resources while the server prepares a final response. /// Returns a result indicating that the server is sending information about early hints that may be used by the client to begin preloading resources while the server prepares a final response.
/// Corresponds to HTTP status code 103 Early Hints. /// Corresponds to HTTP status code 103 Early Hints.
/// </summary> /// </summary>
public static Result<T> EarlyHints(T? value, string message) => public static Result<T> EarlyHints(T? value, params string [] messages) {
EarlyHints(value, new List<string> { message }); return new Result<T>(value, true, [..messages], (HttpStatusCode)103); // Early Hints is not defined in HttpStatusCode enum, 103 is the official code
/// <summary>
/// Returns a result indicating that the server is sending information about early hints that may be used by the client to begin preloading resources while the server prepares a final response.
/// Corresponds to HTTP status code 103 Early Hints.
/// </summary>
public static Result<T> EarlyHints(T? value, List<string> messages) {
return new Result<T>(value, true, messages, (HttpStatusCode)103); // Early Hints is not defined in HttpStatusCode enum, 103 is the official code
} }
} }

View File

@ -9,120 +9,64 @@ public partial class Result {
/// Returns a result indicating that the request has multiple options, and the user or user-agent should select one of them. /// Returns a result indicating that the request has multiple options, and the user or user-agent should select one of them.
/// Corresponds to HTTP status code 300 Multiple Choices. /// Corresponds to HTTP status code 300 Multiple Choices.
/// </summary> /// </summary>
public static Result MultipleChoices(string message) => public static Result MultipleChoices(params string [] messages) {
MultipleChoices(new List<string> { message }); return new Result(true, [..messages], HttpStatusCode.MultipleChoices);
/// <summary>
/// Returns a result indicating that the request has multiple options, and the user or user-agent should select one of them.
/// Corresponds to HTTP status code 300 Multiple Choices.
/// </summary>
public static Result MultipleChoices(List<string> messages) {
return new Result(true, messages, HttpStatusCode.MultipleChoices);
} }
/// <summary> /// <summary>
/// Returns a result indicating that the requested resource has been permanently moved to a new URI. /// Returns a result indicating that the requested resource has been permanently moved to a new URI.
/// Corresponds to HTTP status code 301 Moved Permanently. /// Corresponds to HTTP status code 301 Moved Permanently.
/// </summary> /// </summary>
public static Result MovedPermanently(string message) => public static Result MovedPermanently(params string [] messages) {
MovedPermanently(new List<string> { message }); return new Result(true, [..messages], HttpStatusCode.MovedPermanently);
/// <summary>
/// Returns a result indicating that the requested resource has been permanently moved to a new URI.
/// Corresponds to HTTP status code 301 Moved Permanently.
/// </summary>
public static Result MovedPermanently(List<string> messages) {
return new Result(true, messages, HttpStatusCode.MovedPermanently);
} }
/// <summary> /// <summary>
/// Returns a result indicating that the requested resource resides temporarily under a different URI. /// Returns a result indicating that the requested resource resides temporarily under a different URI.
/// Corresponds to HTTP status code 302 Found. /// Corresponds to HTTP status code 302 Found.
/// </summary> /// </summary>
public static Result Found(string message) => public static Result Found(params string [] messages) {
Found(new List<string> { message }); return new Result(true, [..messages], HttpStatusCode.Found);
/// <summary>
/// Returns a result indicating that the requested resource resides temporarily under a different URI.
/// Corresponds to HTTP status code 302 Found.
/// </summary>
public static Result Found(List<string> messages) {
return new Result(true, messages, HttpStatusCode.Found);
} }
/// <summary> /// <summary>
/// Returns a result indicating that the response to the request can be found under another URI using the GET method. /// Returns a result indicating that the response to the request can be found under another URI using the GET method.
/// Corresponds to HTTP status code 303 See Other. /// Corresponds to HTTP status code 303 See Other.
/// </summary> /// </summary>
public static Result SeeOther(string message) => public static Result SeeOther(params string [] messages) {
SeeOther(new List<string> { message }); return new Result(true, [..messages], HttpStatusCode.SeeOther);
/// <summary>
/// Returns a result indicating that the response to the request can be found under another URI using the GET method.
/// Corresponds to HTTP status code 303 See Other.
/// </summary>
public static Result SeeOther(List<string> messages) {
return new Result(true, messages, HttpStatusCode.SeeOther);
} }
/// <summary> /// <summary>
/// Returns a result indicating that the requested resource has not been modified since the last request. /// Returns a result indicating that the requested resource has not been modified since the last request.
/// Corresponds to HTTP status code 304 Not Modified. /// Corresponds to HTTP status code 304 Not Modified.
/// </summary> /// </summary>
public static Result NotModified(string message) => public static Result NotModified(params string [] messages) {
NotModified(new List<string> { message }); return new Result(true, [..messages], HttpStatusCode.NotModified);
/// <summary>
/// Returns a result indicating that the requested resource has not been modified since the last request.
/// Corresponds to HTTP status code 304 Not Modified.
/// </summary>
public static Result NotModified(List<string> messages) {
return new Result(true, messages, HttpStatusCode.NotModified);
} }
/// <summary> /// <summary>
/// Returns a result indicating that the requested resource must be accessed through the proxy given by the location field. /// Returns a result indicating that the requested resource must be accessed through the proxy given by the location field.
/// Corresponds to HTTP status code 305 Use Proxy. /// Corresponds to HTTP status code 305 Use Proxy.
/// </summary> /// </summary>
public static Result UseProxy(string message) => public static Result UseProxy(params string [] messages) {
UseProxy(new List<string> { message }); return new Result(true, [..messages], HttpStatusCode.UseProxy);
/// <summary>
/// Returns a result indicating that the requested resource must be accessed through the proxy given by the location field.
/// Corresponds to HTTP status code 305 Use Proxy.
/// </summary>
public static Result UseProxy(List<string> messages) {
return new Result(true, messages, HttpStatusCode.UseProxy);
} }
/// <summary> /// <summary>
/// Returns a result indicating that the requested resource resides temporarily under a different URI, but future requests should still use the original URI. /// Returns a result indicating that the requested resource resides temporarily under a different URI, but future requests should still use the original URI.
/// Corresponds to HTTP status code 307 Temporary Redirect. /// Corresponds to HTTP status code 307 Temporary Redirect.
/// </summary> /// </summary>
public static Result TemporaryRedirect(string message) => public static Result TemporaryRedirect(params string [] messages) {
TemporaryRedirect(new List<string> { message }); return new Result(true, [..messages], HttpStatusCode.TemporaryRedirect);
/// <summary>
/// Returns a result indicating that the requested resource resides temporarily under a different URI, but future requests should still use the original URI.
/// Corresponds to HTTP status code 307 Temporary Redirect.
/// </summary>
public static Result TemporaryRedirect(List<string> messages) {
return new Result(true, messages, HttpStatusCode.TemporaryRedirect);
} }
/// <summary> /// <summary>
/// Returns a result indicating that the requested resource has been permanently moved to a new URI, and future references should use the new URI. /// Returns a result indicating that the requested resource has been permanently moved to a new URI, and future references should use the new URI.
/// Corresponds to HTTP status code 308 Permanent Redirect. /// Corresponds to HTTP status code 308 Permanent Redirect.
/// </summary> /// </summary>
public static Result PermanentRedirect(string message) => public static Result PermanentRedirect(params string [] messages) {
PermanentRedirect(new List<string> { message }); return new Result(true, [..messages], HttpStatusCode.PermanentRedirect);
/// <summary>
/// Returns a result indicating that the requested resource has been permanently moved to a new URI, and future references should use the new URI.
/// Corresponds to HTTP status code 308 Permanent Redirect.
/// </summary>
public static Result PermanentRedirect(List<string> messages) {
return new Result(true, messages, HttpStatusCode.PermanentRedirect);
} }
} }
@ -132,119 +76,63 @@ public partial class Result<T> : Result {
/// Returns a result indicating that the request has multiple options, and the user or user-agent should select one of them. /// Returns a result indicating that the request has multiple options, and the user or user-agent should select one of them.
/// Corresponds to HTTP status code 300 Multiple Choices. /// Corresponds to HTTP status code 300 Multiple Choices.
/// </summary> /// </summary>
public static Result<T> MultipleChoices(T? value, string message) => public static Result<T> MultipleChoices(T? value, params string [] messages) {
MultipleChoices(value, new List<string> { message }); return new Result<T>(value, true, [..messages], HttpStatusCode.MultipleChoices);
/// <summary>
/// Returns a result indicating that the request has multiple options, and the user or user-agent should select one of them.
/// Corresponds to HTTP status code 300 Multiple Choices.
/// </summary>
public static Result<T> MultipleChoices(T? value, List<string> messages) {
return new Result<T>(value, true, messages, HttpStatusCode.MultipleChoices);
} }
/// <summary> /// <summary>
/// Returns a result indicating that the requested resource has been permanently moved to a new URI. /// Returns a result indicating that the requested resource has been permanently moved to a new URI.
/// Corresponds to HTTP status code 301 Moved Permanently. /// Corresponds to HTTP status code 301 Moved Permanently.
/// </summary> /// </summary>
public static Result<T> MovedPermanently(T? value, string message) => public static Result<T> MovedPermanently(T? value, params string [] messages) {
MovedPermanently(value, new List<string> { message }); return new Result<T>(value, true, [..messages], HttpStatusCode.MovedPermanently);
/// <summary>
/// Returns a result indicating that the requested resource has been permanently moved to a new URI.
/// Corresponds to HTTP status code 301 Moved Permanently.
/// </summary>
public static Result<T> MovedPermanently(T? value, List<string> messages) {
return new Result<T>(value, true, messages, HttpStatusCode.MovedPermanently);
} }
/// <summary> /// <summary>
/// Returns a result indicating that the requested resource resides temporarily under a different URI. /// Returns a result indicating that the requested resource resides temporarily under a different URI.
/// Corresponds to HTTP status code 302 Found. /// Corresponds to HTTP status code 302 Found.
/// </summary> /// </summary>
public static Result<T> Found(T? value, string message) => public static Result<T> Found(T? value, params string [] messages) {
Found(value, new List<string> { message }); return new Result<T>(value, true, [..messages], HttpStatusCode.Found);
/// <summary>
/// Returns a result indicating that the requested resource resides temporarily under a different URI.
/// Corresponds to HTTP status code 302 Found.
/// </summary>
public static Result<T> Found(T? value, List<string> messages) {
return new Result<T>(value, true, messages, HttpStatusCode.Found);
} }
/// <summary> /// <summary>
/// Returns a result indicating that the response to the request can be found under another URI using the GET method. /// Returns a result indicating that the response to the request can be found under another URI using the GET method.
/// Corresponds to HTTP status code 303 See Other. /// Corresponds to HTTP status code 303 See Other.
/// </summary> /// </summary>
public static Result<T> SeeOther(T? value, string message) => public static Result<T> SeeOther(T? value, params string [] messages) {
SeeOther(value, new List<string> { message }); return new Result<T>(value, true, [..messages], HttpStatusCode.SeeOther);
/// <summary>
/// Returns a result indicating that the response to the request can be found under another URI using the GET method.
/// Corresponds to HTTP status code 303 See Other.
/// </summary>
public static Result<T> SeeOther(T? value, List<string> messages) {
return new Result<T>(value, true, messages, HttpStatusCode.SeeOther);
} }
/// <summary> /// <summary>
/// Returns a result indicating that the requested resource has not been modified since the last request. /// Returns a result indicating that the requested resource has not been modified since the last request.
/// Corresponds to HTTP status code 304 Not Modified. /// Corresponds to HTTP status code 304 Not Modified.
/// </summary> /// </summary>
public static Result<T> NotModified(T? value, string message) => public static Result<T> NotModified(T? value, params string [] messages) {
NotModified(value, new List<string> { message }); return new Result<T>(value, true, [..messages], HttpStatusCode.NotModified);
/// <summary>
/// Returns a result indicating that the requested resource has not been modified since the last request.
/// Corresponds to HTTP status code 304 Not Modified.
/// </summary>
public static Result<T> NotModified(T? value, List<string> messages) {
return new Result<T>(value, true, messages, HttpStatusCode.NotModified);
} }
/// <summary> /// <summary>
/// Returns a result indicating that the requested resource must be accessed through the proxy given by the location field. /// Returns a result indicating that the requested resource must be accessed through the proxy given by the location field.
/// Corresponds to HTTP status code 305 Use Proxy. /// Corresponds to HTTP status code 305 Use Proxy.
/// </summary> /// </summary>
public static Result<T> UseProxy(T? value, string message) => public static Result<T> UseProxy(T? value, params string [] messages) {
UseProxy(value, new List<string> { message }); return new Result<T>(value, true, [..messages], HttpStatusCode.UseProxy);
/// <summary>
/// Returns a result indicating that the requested resource must be accessed through the proxy given by the location field.
/// Corresponds to HTTP status code 305 Use Proxy.
/// </summary>
public static Result<T> UseProxy(T? value, List<string> messages) {
return new Result<T>(value, true, messages, HttpStatusCode.UseProxy);
} }
/// <summary> /// <summary>
/// Returns a result indicating that the requested resource resides temporarily under a different URI, but future requests should still use the original URI. /// Returns a result indicating that the requested resource resides temporarily under a different URI, but future requests should still use the original URI.
/// Corresponds to HTTP status code 307 Temporary Redirect. /// Corresponds to HTTP status code 307 Temporary Redirect.
/// </summary> /// </summary>
public static Result<T> TemporaryRedirect(T? value, string message) => public static Result<T> TemporaryRedirect(T? value, params string [] messages) {
TemporaryRedirect(value, new List<string> { message }); return new Result<T>(value, true, [..messages], HttpStatusCode.TemporaryRedirect);
/// <summary>
/// Returns a result indicating that the requested resource resides temporarily under a different URI, but future requests should still use the original URI.
/// Corresponds to HTTP status code 307 Temporary Redirect.
/// </summary>
public static Result<T> TemporaryRedirect(T? value, List<string> messages) {
return new Result<T>(value, true, messages, HttpStatusCode.TemporaryRedirect);
} }
/// <summary> /// <summary>
/// Returns a result indicating that the requested resource has been permanently moved to a new URI, and future references should use the new URI. /// Returns a result indicating that the requested resource has been permanently moved to a new URI, and future references should use the new URI.
/// Corresponds to HTTP status code 308 Permanent Redirect. /// Corresponds to HTTP status code 308 Permanent Redirect.
/// </summary> /// </summary>
public static Result<T> PermanentRedirect(T? value, string message) => public static Result<T> PermanentRedirect(T? value, params string [] messages) {
PermanentRedirect(value, new List<string> { message }); return new Result<T>(value, true, [..messages], HttpStatusCode.PermanentRedirect);
/// <summary>
/// Returns a result indicating that the requested resource has been permanently moved to a new URI, and future references should use the new URI.
/// Corresponds to HTTP status code 308 Permanent Redirect.
/// </summary>
public static Result<T> PermanentRedirect(T? value, List<string> messages) {
return new Result<T>(value, true, messages, HttpStatusCode.PermanentRedirect);
} }
} }

View File

@ -8,165 +8,88 @@ public partial class Result {
/// Returns a result indicating the server encountered an unexpected condition that prevented it from fulfilling the request. /// Returns a result indicating the server encountered an unexpected condition that prevented it from fulfilling the request.
/// Corresponds to HTTP status code 500 Internal Server Error. /// Corresponds to HTTP status code 500 Internal Server Error.
/// </summary> /// </summary>
public static Result InternalServerError(string message) => public static Result InternalServerError(params string [] messages) {
InternalServerError(new List<string> { message }); return new Result(false, [..messages], HttpStatusCode.InternalServerError);
/// <summary>
/// Returns a result indicating the server encountered an unexpected condition that prevented it from fulfilling the request.
/// Corresponds to HTTP status code 500 Internal Server Error.
/// </summary>
public static Result InternalServerError(List<string> messages) {
return new Result(false, messages, HttpStatusCode.InternalServerError);
} }
/// <summary> /// <summary>
/// Returns a result indicating the server does not support the functionality required to fulfill the request. /// Returns a result indicating the server does not support the functionality required to fulfill the request.
/// Corresponds to HTTP status code 501 Not Implemented. /// Corresponds to HTTP status code 501 Not Implemented.
/// </summary> /// </summary>
public static Result NotImplemented(string message) => public static Result NotImplemented(params string [] messages) {
NotImplemented(new List<string> { message }); return new Result(false, [..messages], HttpStatusCode.NotImplemented);
/// <summary>
/// Returns a result indicating the server does not support the functionality required to fulfill the request.
/// Corresponds to HTTP status code 501 Not Implemented.
/// </summary>
public static Result NotImplemented(List<string> messages) {
return new Result(false, messages, HttpStatusCode.NotImplemented);
} }
/// <summary> /// <summary>
/// Returns a result indicating the server, while acting as a gateway or proxy, received an invalid response from the upstream server. /// Returns a result indicating the server, while acting as a gateway or proxy, received an invalid response from the upstream server.
/// Corresponds to HTTP status code 502 Bad Gateway. /// Corresponds to HTTP status code 502 Bad Gateway.
/// </summary> /// </summary>
public static Result BadGateway(string message) => public static Result BadGateway(params string [] messages) {
BadGateway(new List<string> { message }); return new Result(false, [..messages], HttpStatusCode.BadGateway);
/// <summary>
/// Returns a result indicating the server, while acting as a gateway or proxy, received an invalid response from the upstream server.
/// Corresponds to HTTP status code 502 Bad Gateway.
/// </summary>
public static Result BadGateway(List<string> messages) {
return new Result(false, messages, HttpStatusCode.BadGateway);
} }
/// <summary> /// <summary>
/// Returns a result indicating the server is currently unable to handle the request due to temporary overload or maintenance of the server. /// Returns a result indicating the server is currently unable to handle the request due to temporary overload or maintenance of the server.
/// Corresponds to HTTP status code 503 Service Unavailable. /// Corresponds to HTTP status code 503 Service Unavailable.
/// </summary> /// </summary>
public static Result ServiceUnavailable(string message) => public static Result ServiceUnavailable(params string [] messages) {
ServiceUnavailable(new List<string> { message }); return new Result(false, [..messages], HttpStatusCode.ServiceUnavailable);
/// <summary>
/// Returns a result indicating the server is currently unable to handle the request due to temporary overload or maintenance of the server.
/// Corresponds to HTTP status code 503 Service Unavailable.
/// </summary>
public static Result ServiceUnavailable(List<string> messages) {
return new Result(false, messages, HttpStatusCode.ServiceUnavailable);
} }
/// <summary> /// <summary>
/// Returns a result indicating the server, while acting as a gateway or proxy, did not receive a timely response from the upstream server. /// Returns a result indicating the server, while acting as a gateway or proxy, did not receive a timely response from the upstream server.
/// Corresponds to HTTP status code 504 Gateway Timeout. /// Corresponds to HTTP status code 504 Gateway Timeout.
/// </summary> /// </summary>
public static Result GatewayTimeout(string message) => public static Result GatewayTimeout(params string [] messages) {
GatewayTimeout(new List<string> { message }); return new Result(false, [..messages], HttpStatusCode.GatewayTimeout);
/// <summary>
/// Returns a result indicating the server, while acting as a gateway or proxy, did not receive a timely response from the upstream server.
/// Corresponds to HTTP status code 504 Gateway Timeout.
/// </summary>
public static Result GatewayTimeout(List<string> messages) {
return new Result(false, messages, HttpStatusCode.GatewayTimeout);
} }
/// <summary> /// <summary>
/// Returns a result indicating the server does not support the HTTP protocol version used in the request. /// Returns a result indicating the server does not support the HTTP protocol version used in the request.
/// Corresponds to HTTP status code 505 HTTP Version Not Supported. /// Corresponds to HTTP status code 505 HTTP Version Not Supported.
/// </summary> /// </summary>
public static Result HttpVersionNotSupported(string message) => public static Result HttpVersionNotSupported(params string [] messages) {
HttpVersionNotSupported(new List<string> { message }); return new Result(false, [..messages], HttpStatusCode.HttpVersionNotSupported);
/// <summary>
/// Returns a result indicating the server does not support the HTTP protocol version used in the request.
/// Corresponds to HTTP status code 505 HTTP Version Not Supported.
/// </summary>
public static Result HttpVersionNotSupported(List<string> messages) {
return new Result(false, messages, HttpStatusCode.HttpVersionNotSupported);
} }
/// <summary> /// <summary>
/// Returns a result indicating the server has an internal configuration error: the chosen variant resource is configured to engage in transparent content negotiation itself, and is therefore not a proper end point in the negotiation process. /// Returns a result indicating the server has an internal configuration error: the chosen variant resource is configured to engage in transparent content negotiation itself, and is therefore not a proper end point in the negotiation process.
/// Corresponds to HTTP status code 506 Variant Also Negotiates. /// Corresponds to HTTP status code 506 Variant Also Negotiates.
/// </summary> /// </summary>
public static Result VariantAlsoNegotiates(string message) => public static Result VariantAlsoNegotiates(params string [] messages) {
VariantAlsoNegotiates(new List<string> { message }); return new Result(false, [..messages], HttpStatusCode.VariantAlsoNegotiates);
/// <summary>
/// Returns a result indicating the server has an internal configuration error: the chosen variant resource is configured to engage in transparent content negotiation itself, and is therefore not a proper end point in the negotiation process.
/// Corresponds to HTTP status code 506 Variant Also Negotiates.
/// </summary>
public static Result VariantAlsoNegotiates(List<string> messages) {
return new Result(false, messages, HttpStatusCode.VariantAlsoNegotiates);
} }
/// <summary> /// <summary>
/// Returns a result indicating the server is unable to store the representation needed to complete the request. /// Returns a result indicating the server is unable to store the representation needed to complete the request.
/// Corresponds to HTTP status code 507 Insufficient Storage. /// Corresponds to HTTP status code 507 Insufficient Storage.
/// </summary> /// </summary>
public static Result InsufficientStorage(string message) => public static Result InsufficientStorage(params string [] messages) {
InsufficientStorage(new List<string> { message }); return new Result(false, [..messages], HttpStatusCode.InsufficientStorage);
/// <summary>
/// Returns a result indicating the server is unable to store the representation needed to complete the request.
/// Corresponds to HTTP status code 507 Insufficient Storage.
/// </summary>
public static Result InsufficientStorage(List<string> messages) {
return new Result(false, messages, HttpStatusCode.InsufficientStorage);
} }
/// <summary> /// <summary>
/// Returns a result indicating the server detected an infinite loop while processing a request with depth: infinity. Usually encountered in WebDAV scenarios. /// Returns a result indicating the server detected an infinite loop while processing a request with depth: infinity. Usually encountered in WebDAV scenarios.
/// Corresponds to HTTP status code 508 Loop Detected. /// Corresponds to HTTP status code 508 Loop Detected.
/// </summary> /// </summary>
public static Result LoopDetected(string message) => public static Result LoopDetected(params string [] messages) {
LoopDetected(new List<string> { message }); return new Result(false, [..messages], HttpStatusCode.LoopDetected);
/// <summary>
/// Returns a result indicating the server detected an infinite loop while processing a request with depth: infinity. Usually encountered in WebDAV scenarios.
/// Corresponds to HTTP status code 508 Loop Detected.
/// </summary>
public static Result LoopDetected(List<string> messages) {
return new Result(false, messages, HttpStatusCode.LoopDetected);
} }
/// <summary> /// <summary>
/// Returns a result indicating further extensions to the request are required for the server to fulfill it. /// Returns a result indicating further extensions to the request are required for the server to fulfill it.
/// Corresponds to HTTP status code 510 Not Extended. /// Corresponds to HTTP status code 510 Not Extended.
/// </summary> /// </summary>
public static Result NotExtended(string message) => public static Result NotExtended(params string [] messages) {
NotExtended(new List<string> { message }); return new Result(false, [..messages], HttpStatusCode.NotExtended);
/// <summary>
/// Returns a result indicating further extensions to the request are required for the server to fulfill it.
/// Corresponds to HTTP status code 510 Not Extended.
/// </summary>
public static Result NotExtended(List<string> messages) {
return new Result(false, messages, HttpStatusCode.NotExtended);
} }
/// <summary> /// <summary>
/// Returns a result indicating the client needs to authenticate to gain network access. /// Returns a result indicating the client needs to authenticate to gain network access.
/// Corresponds to HTTP status code 511 Network Authentication Required. /// Corresponds to HTTP status code 511 Network Authentication Required.
/// </summary> /// </summary>
public static Result NetworkAuthenticationRequired(string message) => public static Result NetworkAuthenticationRequired(params string [] messages) {
NetworkAuthenticationRequired(new List<string> { message }); return new Result(false, [..messages], HttpStatusCode.NetworkAuthenticationRequired);
/// <summary>
/// Returns a result indicating the client needs to authenticate to gain network access.
/// Corresponds to HTTP status code 511 Network Authentication Required.
/// </summary>
public static Result NetworkAuthenticationRequired(List<string> messages) {
return new Result(false, messages, HttpStatusCode.NetworkAuthenticationRequired);
} }
} }
@ -176,164 +99,87 @@ public partial class Result<T> : Result {
/// Returns a result indicating the server encountered an unexpected condition that prevented it from fulfilling the request. /// Returns a result indicating the server encountered an unexpected condition that prevented it from fulfilling the request.
/// Corresponds to HTTP status code 500 Internal Server Error. /// Corresponds to HTTP status code 500 Internal Server Error.
/// </summary> /// </summary>
public static Result<T> InternalServerError(T? value, string message) => public static Result<T> InternalServerError(T? value, params string [] messages) {
InternalServerError(value, new List<string> { message }); return new Result<T>(value, false, [..messages], HttpStatusCode.InternalServerError);
/// <summary>
/// Returns a result indicating the server encountered an unexpected condition that prevented it from fulfilling the request.
/// Corresponds to HTTP status code 500 Internal Server Error.
/// </summary>
public static Result<T> InternalServerError(T? value, List<string> messages) {
return new Result<T>(value, false, messages, HttpStatusCode.InternalServerError);
} }
/// <summary> /// <summary>
/// Returns a result indicating the server does not support the functionality required to fulfill the request. /// Returns a result indicating the server does not support the functionality required to fulfill the request.
/// Corresponds to HTTP status code 501 Not Implemented. /// Corresponds to HTTP status code 501 Not Implemented.
/// </summary> /// </summary>
public static Result<T> NotImplemented(T? value, string message) => public static Result<T> NotImplemented(T? value, params string [] messages) {
NotImplemented(value, new List<string> { message }); return new Result<T>(value, false, [..messages], HttpStatusCode.NotImplemented);
/// <summary>
/// Returns a result indicating the server does not support the functionality required to fulfill the request.
/// Corresponds to HTTP status code 501 Not Implemented.
/// </summary>
public static Result<T> NotImplemented(T? value, List<string> messages) {
return new Result<T>(value, false, messages, HttpStatusCode.NotImplemented);
} }
/// <summary> /// <summary>
/// Returns a result indicating the server, while acting as a gateway or proxy, received an invalid response from the upstream server. /// Returns a result indicating the server, while acting as a gateway or proxy, received an invalid response from the upstream server.
/// Corresponds to HTTP status code 502 Bad Gateway. /// Corresponds to HTTP status code 502 Bad Gateway.
/// </summary> /// </summary>
public static Result<T> BadGateway(T? value, string message) => public static Result<T> BadGateway(T? value, params string [] messages) {
BadGateway(value, new List<string> { message }); return new Result<T>(value, false, [..messages], HttpStatusCode.BadGateway);
/// <summary>
/// Returns a result indicating the server, while acting as a gateway or proxy, received an invalid response from the upstream server.
/// Corresponds to HTTP status code 502 Bad Gateway.
/// </summary>
public static Result<T> BadGateway(T? value, List<string> messages) {
return new Result<T>(value, false, messages, HttpStatusCode.BadGateway);
} }
/// <summary> /// <summary>
/// Returns a result indicating the server is currently unable to handle the request due to temporary overload or maintenance of the server. /// Returns a result indicating the server is currently unable to handle the request due to temporary overload or maintenance of the server.
/// Corresponds to HTTP status code 503 Service Unavailable. /// Corresponds to HTTP status code 503 Service Unavailable.
/// </summary> /// </summary>
public static Result<T> ServiceUnavailable(T? value, string message) => public static Result<T> ServiceUnavailable(T? value, params string [] messages) {
ServiceUnavailable(value, new List<string> { message }); return new Result<T>(value, false, [..messages], HttpStatusCode.ServiceUnavailable);
/// <summary>
/// Returns a result indicating the server is currently unable to handle the request due to temporary overload or maintenance of the server.
/// Corresponds to HTTP status code 503 Service Unavailable.
/// </summary>
public static Result<T> ServiceUnavailable(T? value, List<string> messages) {
return new Result<T>(value, false, messages, HttpStatusCode.ServiceUnavailable);
} }
/// <summary> /// <summary>
/// Returns a result indicating the server, while acting as a gateway or proxy, did not receive a timely response from the upstream server. /// Returns a result indicating the server, while acting as a gateway or proxy, did not receive a timely response from the upstream server.
/// Corresponds to HTTP status code 504 Gateway Timeout. /// Corresponds to HTTP status code 504 Gateway Timeout.
/// </summary> /// </summary>
public static Result<T> GatewayTimeout(T? value, string message) => public static Result<T> GatewayTimeout(T? value, params string [] messages) {
GatewayTimeout(value, new List<string> { message }); return new Result<T>(value, false, [..messages], HttpStatusCode.GatewayTimeout);
/// <summary>
/// Returns a result indicating the server, while acting as a gateway or proxy, did not receive a timely response from the upstream server.
/// Corresponds to HTTP status code 504 Gateway Timeout.
/// </summary>
public static Result<T> GatewayTimeout(T? value, List<string> messages) {
return new Result<T>(value, false, messages, HttpStatusCode.GatewayTimeout);
} }
/// <summary> /// <summary>
/// Returns a result indicating the server does not support the HTTP protocol version used in the request. /// Returns a result indicating the server does not support the HTTP protocol version used in the request.
/// Corresponds to HTTP status code 505 HTTP Version Not Supported. /// Corresponds to HTTP status code 505 HTTP Version Not Supported.
/// </summary> /// </summary>
public static Result<T> HttpVersionNotSupported(T? value, string message) => public static Result<T> HttpVersionNotSupported(T? value, params string [] messages) {
HttpVersionNotSupported(value, new List<string> { message }); return new Result<T>(value, false, [..messages], HttpStatusCode.HttpVersionNotSupported);
/// <summary>
/// Returns a result indicating the server does not support the HTTP protocol version used in the request.
/// Corresponds to HTTP status code 505 HTTP Version Not Supported.
/// </summary>
public static Result<T> HttpVersionNotSupported(T? value, List<string> messages) {
return new Result<T>(value, false, messages, HttpStatusCode.HttpVersionNotSupported);
} }
/// <summary> /// <summary>
/// Returns a result indicating the server has an internal configuration error: the chosen variant resource is configured to engage in transparent content negotiation itself, and is therefore not a proper end point in the negotiation process. /// Returns a result indicating the server has an internal configuration error: the chosen variant resource is configured to engage in transparent content negotiation itself, and is therefore not a proper end point in the negotiation process.
/// Corresponds to HTTP status code 506 Variant Also Negotiates. /// Corresponds to HTTP status code 506 Variant Also Negotiates.
/// </summary> /// </summary>
public static Result<T> VariantAlsoNegotiates(T? value, string message) => public static Result<T> VariantAlsoNegotiates(T? value, params string [] messages) {
VariantAlsoNegotiates(value, new List<string> { message }); return new Result<T>(value, false, [..messages], HttpStatusCode.VariantAlsoNegotiates);
/// <summary>
/// Returns a result indicating the server has an internal configuration error: the chosen variant resource is configured to engage in transparent content negotiation itself, and is therefore not a proper end point in the negotiation process.
/// Corresponds to HTTP status code 506 Variant Also Negotiates.
/// </summary>
public static Result<T> VariantAlsoNegotiates(T? value, List<string> messages) {
return new Result<T>(value, false, messages, HttpStatusCode.VariantAlsoNegotiates);
} }
/// <summary> /// <summary>
/// Returns a result indicating the server is unable to store the representation needed to complete the request. /// Returns a result indicating the server is unable to store the representation needed to complete the request.
/// Corresponds to HTTP status code 507 Insufficient Storage. /// Corresponds to HTTP status code 507 Insufficient Storage.
/// </summary> /// </summary>
public static Result<T> InsufficientStorage(T? value, string message) => public static Result<T> InsufficientStorage(T? value, params string [] messages) {
InsufficientStorage(value, new List<string> { message }); return new Result<T>(value, false, [..messages], HttpStatusCode.InsufficientStorage);
/// <summary>
/// Returns a result indicating the server is unable to store the representation needed to complete the request.
/// Corresponds to HTTP status code 507 Insufficient Storage.
/// </summary>
public static Result<T> InsufficientStorage(T? value, List<string> messages) {
return new Result<T>(value, false, messages, HttpStatusCode.InsufficientStorage);
} }
/// <summary> /// <summary>
/// Returns a result indicating the server detected an infinite loop while processing a request with depth: infinity. Usually encountered in WebDAV scenarios. /// Returns a result indicating the server detected an infinite loop while processing a request with depth: infinity. Usually encountered in WebDAV scenarios.
/// Corresponds to HTTP status code 508 Loop Detected. /// Corresponds to HTTP status code 508 Loop Detected.
/// </summary> /// </summary>
public static Result<T> LoopDetected(T? value, string message) => public static Result<T> LoopDetected(T? value, params string [] messages) {
LoopDetected(value, new List<string> { message }); return new Result<T>(value, false, [..messages], HttpStatusCode.LoopDetected);
/// <summary>
/// Returns a result indicating the server detected an infinite loop while processing a request with depth: infinity. Usually encountered in WebDAV scenarios.
/// Corresponds to HTTP status code 508 Loop Detected.
/// </summary>
public static Result<T> LoopDetected(T? value, List<string> messages) {
return new Result<T>(value, false, messages, HttpStatusCode.LoopDetected);
} }
/// <summary> /// <summary>
/// Returns a result indicating further extensions to the request are required for the server to fulfill it. /// Returns a result indicating further extensions to the request are required for the server to fulfill it.
/// Corresponds to HTTP status code 510 Not Extended. /// Corresponds to HTTP status code 510 Not Extended.
/// </summary> /// </summary>
public static Result<T> NotExtended(T? value, string message) => public static Result<T> NotExtended(T? value, params string [] messages) {
NotExtended(value, new List<string> { message }); return new Result<T>(value, false, [..messages], HttpStatusCode.NotExtended);
/// <summary>
/// Returns a result indicating further extensions to the request are required for the server to fulfill it.
/// Corresponds to HTTP status code 510 Not Extended.
/// </summary>
public static Result<T> NotExtended(T? value, List<string> messages) {
return new Result<T>(value, false, messages, HttpStatusCode.NotExtended);
} }
/// <summary> /// <summary>
/// Returns a result indicating the client needs to authenticate to gain network access. /// Returns a result indicating the client needs to authenticate to gain network access.
/// Corresponds to HTTP status code 511 Network Authentication Required. /// Corresponds to HTTP status code 511 Network Authentication Required.
/// </summary> /// </summary>
public static Result<T> NetworkAuthenticationRequired(T? value, string message) => public static Result<T> NetworkAuthenticationRequired(T? value, params string [] messages) {
NetworkAuthenticationRequired(value, new List<string> { message }); return new Result<T>(value, false, [..messages], HttpStatusCode.NetworkAuthenticationRequired);
/// <summary>
/// Returns a result indicating the client needs to authenticate to gain network access.
/// Corresponds to HTTP status code 511 Network Authentication Required.
/// </summary>
public static Result<T> NetworkAuthenticationRequired(T? value, List<string> messages) {
return new Result<T>(value, false, messages, HttpStatusCode.NetworkAuthenticationRequired);
} }
} }

View File

@ -9,150 +9,80 @@ public partial class Result {
/// Returns a result indicating the request was successful and the server returned the requested data. /// Returns a result indicating the request was successful and the server returned the requested data.
/// Corresponds to HTTP status code 200 OK. /// Corresponds to HTTP status code 200 OK.
/// </summary> /// </summary>
public static Result Ok(string? message = null) => public static Result Ok(params string[] messages) {
Ok(messages: message != null ? [message] : null); return new Result(true, [..messages], HttpStatusCode.OK);
/// <summary>
/// Returns a result indicating the request was successful and the server returned the requested data.
/// Corresponds to HTTP status code 200 OK.
/// </summary>
public static Result Ok(List<string>? messages = null) {
return new Result(true, messages ?? [], HttpStatusCode.OK);
} }
/// <summary> /// <summary>
/// Returns a result indicating the request was successful and a new resource was created. /// Returns a result indicating the request was successful and a new resource was created.
/// Corresponds to HTTP status code 201 Created. /// Corresponds to HTTP status code 201 Created.
/// </summary> /// </summary>
public static Result Created(string? message = null) => public static Result Created(params string[] messages) {
Created(messages: message != null ? [message] : null); return new Result(true, [..messages], HttpStatusCode.Created);
/// <summary>
/// Returns a result indicating the request was successful and a new resource was created.
/// Corresponds to HTTP status code 201 Created.
/// </summary>
public static Result Created(List<string>? messages = null) {
return new Result(true, messages ?? [], HttpStatusCode.Created);
} }
/// <summary> /// <summary>
/// Returns a result indicating the request has been accepted for processing, but the processing is not yet complete. /// Returns a result indicating the request has been accepted for processing, but the processing is not yet complete.
/// Corresponds to HTTP status code 202 Accepted. /// Corresponds to HTTP status code 202 Accepted.
/// </summary> /// </summary>
public static Result Accepted(string? message = null) => public static Result Accepted(params string[] messages) {
Accepted(messages: message != null ? [message] : null); return new Result(true, [..messages], HttpStatusCode.Accepted);
/// <summary>
/// Returns a result indicating the request has been accepted for processing, but the processing is not yet complete.
/// Corresponds to HTTP status code 202 Accepted.
/// </summary>
public static Result Accepted(List<string>? messages = null) {
return new Result(true, messages ?? [], HttpStatusCode.Accepted);
} }
/// <summary> /// <summary>
/// Returns a result indicating the request was successful but the response contains metadata from a source other than the origin server. /// Returns a result indicating the request was successful but the response contains metadata from a source other than the origin server.
/// Corresponds to HTTP status code 203 Non-Authoritative Information. /// Corresponds to HTTP status code 203 Non-Authoritative Information.
/// </summary> /// </summary>
public static Result NonAuthoritativeInformation(string? message = null) => public static Result NonAuthoritativeInformation(params string[] messages) {
NonAuthoritativeInformation(messages: message != null ? [message] : null); return new Result(true, [..messages], HttpStatusCode.NonAuthoritativeInformation);
/// <summary>
/// Returns a result indicating the request was successful but the response contains metadata from a source other than the origin server.
/// Corresponds to HTTP status code 203 Non-Authoritative Information.
/// </summary>
public static Result NonAuthoritativeInformation(List<string>? messages = null) {
return new Result(true, messages ?? [], HttpStatusCode.NonAuthoritativeInformation);
} }
/// <summary> /// <summary>
/// Returns a result indicating the request was successful but there is no content to send in the response. /// Returns a result indicating the request was successful but there is no content to send in the response.
/// Corresponds to HTTP status code 204 No Content. /// Corresponds to HTTP status code 204 No Content.
/// </summary> /// </summary>
public static Result NoContent(string? message = null) => public static Result NoContent(params string[] messages) {
ResetContent(messages: message != null ? [message] : null); return new Result(true, [..messages], HttpStatusCode.NoContent);
/// <summary>
/// Returns a result indicating the request was successful but there is no content to send in the response.
/// Corresponds to HTTP status code 204 No Content.
/// </summary>
public static Result NoContent(List<string>? messages = null) {
return new Result(true, messages ?? [], HttpStatusCode.NoContent);
} }
/// <summary> /// <summary>
/// Returns a result indicating the request was successful, but the user-agent should reset the document view that caused the request. /// Returns a result indicating the request was successful, but the user-agent should reset the document view that caused the request.
/// Corresponds to HTTP status code 205 Reset Content. /// Corresponds to HTTP status code 205 Reset Content.
/// </summary> /// </summary>
public static Result ResetContent(string? message = null) => public static Result ResetContent(params string[] messages) {
ResetContent(messages: message != null ? [message] : null); return new Result(true, [..messages], HttpStatusCode.ResetContent);
/// <summary>
/// Returns a result indicating the request was successful, but the user-agent should reset the document view that caused the request.
/// Corresponds to HTTP status code 205 Reset Content.
/// </summary>
public static Result ResetContent(List<string>? messages = null) {
return new Result(true, messages ?? [], HttpStatusCode.ResetContent);
} }
/// <summary> /// <summary>
/// Returns a result indicating the request was successful and the server is delivering only part of the resource due to a range header sent by the client. /// Returns a result indicating the request was successful and the server is delivering only part of the resource due to a range header sent by the client.
/// Corresponds to HTTP status code 206 Partial Content. /// Corresponds to HTTP status code 206 Partial Content.
/// </summary> /// </summary>
public static Result PartialContent(string? message = null) => public static Result PartialContent(params string[] messages) {
PartialContent(messages: message != null ? [message] : null); return new Result(true, [..messages], HttpStatusCode.PartialContent);
/// <summary>
/// Returns a result indicating the request was successful and the server is delivering only part of the resource due to a range header sent by the client.
/// Corresponds to HTTP status code 206 Partial Content.
/// </summary>
public static Result PartialContent(List<string>? messages = null) {
return new Result(true, messages ?? [], HttpStatusCode.PartialContent);
} }
/// <summary> /// <summary>
/// Returns a result indicating the request was successful and the response contains multiple status codes, typically used for WebDAV. /// Returns a result indicating the request was successful and the response contains multiple status codes, typically used for WebDAV.
/// Corresponds to HTTP status code 207 Multi-Status. /// Corresponds to HTTP status code 207 Multi-Status.
/// </summary> /// </summary>
public static Result MultiStatus(string? message = null) => public static Result MultiStatus(params string[] messages) {
MultiStatus(messages: message != null ? [message] : null); return new Result(true, [..messages], HttpStatusCode.MultiStatus);
/// <summary>
/// Returns a result indicating the request was successful and the response contains multiple status codes, typically used for WebDAV.
/// Corresponds to HTTP status code 207 Multi-Status.
/// </summary>
public static Result MultiStatus(List<string>? messages = null) {
return new Result(true, messages ?? [], HttpStatusCode.MultiStatus);
} }
/// <summary> /// <summary>
/// Returns a result indicating the request was successful and the information has already been reported in a previous response. /// Returns a result indicating the request was successful and the information has already been reported in a previous response.
/// Corresponds to HTTP status code 208 Already Reported. /// Corresponds to HTTP status code 208 Already Reported.
/// </summary> /// </summary>
public static Result AlreadyReported(string? message = null) => public static Result AlreadyReported(params string[] messages) {
AlreadyReported(messages: message != null ? [message] : null); return new Result(true, [..messages], HttpStatusCode.AlreadyReported);
/// <summary>
/// Returns a result indicating the request was successful and the information has already been reported in a previous response.
/// Corresponds to HTTP status code 208 Already Reported.
/// </summary>
public static Result AlreadyReported(List<string>? messages = null) {
return new Result(true, messages ?? [], HttpStatusCode.AlreadyReported);
} }
/// <summary> /// <summary>
/// Returns a result indicating the request was successful and the server fulfilled the request for the resource using the delta encoding method. /// Returns a result indicating the request was successful and the server fulfilled the request for the resource using the delta encoding method.
/// Corresponds to HTTP status code 226 IM Used. /// Corresponds to HTTP status code 226 IM Used.
/// </summary> /// </summary>
public static Result IMUsed(string? message = null) => public static Result IMUsed(params string[] messages) {
IMUsed(messages: message != null ? [message] : null); return new Result(true, [..messages], (HttpStatusCode)226); // 226 is the official status code for IM Used
/// <summary>
/// Returns a result indicating the request was successful and the server fulfilled the request for the resource using the delta encoding method.
/// Corresponds to HTTP status code 226 IM Used.
/// </summary>
public static Result IMUsed(List<string>? messages = null) {
return new Result(true, messages ?? [], (HttpStatusCode)226); // 226 is the official status code for IM Used
} }
} }
public partial class Result<T> : Result { public partial class Result<T> : Result {
@ -161,149 +91,79 @@ public partial class Result<T> : Result {
/// Returns a result indicating the request was successful and the server returned the requested data. /// Returns a result indicating the request was successful and the server returned the requested data.
/// Corresponds to HTTP status code 200 OK. /// Corresponds to HTTP status code 200 OK.
/// </summary> /// </summary>
public static Result<T> Ok(T? value, string? message = null) => public static Result<T> Ok(T? value, params string[] messages) {
Ok(value, messages: message != null ? [message] : null); return new Result<T>(value, true, [..messages], HttpStatusCode.OK);
/// <summary>
/// Returns a result indicating the request was successful and the server returned the requested data.
/// Corresponds to HTTP status code 200 OK.
/// </summary>
public static Result<T> Ok(T? value, List<string>? messages = null) {
return new Result<T>(value, true, messages ?? [], HttpStatusCode.OK);
} }
/// <summary> /// <summary>
/// Returns a result indicating the request was successful and a new resource was created. /// Returns a result indicating the request was successful and a new resource was created.
/// Corresponds to HTTP status code 201 Created. /// Corresponds to HTTP status code 201 Created.
/// </summary> /// </summary>
public static Result<T> Created(T? value, string? message = null) => public static Result<T> Created(T? value, params string[] messages) {
Created(value, messages: message != null ? [message] : null); return new Result<T>(value, true, [..messages], HttpStatusCode.Created);
/// <summary>
/// Returns a result indicating the request was successful and a new resource was created.
/// Corresponds to HTTP status code 201 Created.
/// </summary>
public static Result<T> Created(T? value, List<string>? messages = null) {
return new Result<T>(value, true, messages ?? [], HttpStatusCode.Created);
} }
/// <summary> /// <summary>
/// Returns a result indicating the request has been accepted for processing, but the processing is not yet complete. /// Returns a result indicating the request has been accepted for processing, but the processing is not yet complete.
/// Corresponds to HTTP status code 202 Accepted. /// Corresponds to HTTP status code 202 Accepted.
/// </summary> /// </summary>
public static Result<T> Accepted(T? value, string? message = null) => public static Result<T> Accepted(T? value, params string[] messages) {
Accepted(value, messages: message != null ? [message] : null); return new Result<T>(value, true, [..messages], HttpStatusCode.Accepted);
/// <summary>
/// Returns a result indicating the request has been accepted for processing, but the processing is not yet complete.
/// Corresponds to HTTP status code 202 Accepted.
/// </summary>
public static Result<T> Accepted(T? value, List<string>? messages = null) {
return new Result<T>(value, true, messages ?? [], HttpStatusCode.Accepted);
} }
/// <summary> /// <summary>
/// Returns a result indicating the request was successful but the response contains metadata from a source other than the origin server. /// Returns a result indicating the request was successful but the response contains metadata from a source other than the origin server.
/// Corresponds to HTTP status code 203 Non-Authoritative Information. /// Corresponds to HTTP status code 203 Non-Authoritative Information.
/// </summary> /// </summary>
public static Result<T> NonAuthoritativeInformation(T? value, string? message = null) => public static Result<T> NonAuthoritativeInformation(T? value, params string[] messages) {
NonAuthoritativeInformation(value, messages: message != null ? [message] : null); return new Result<T>(value, true, [..messages], HttpStatusCode.NonAuthoritativeInformation);
/// <summary>
/// Returns a result indicating the request was successful but the response contains metadata from a source other than the origin server.
/// Corresponds to HTTP status code 203 Non-Authoritative Information.
/// </summary>
public static Result<T> NonAuthoritativeInformation(T? value, List<string>? messages = null) {
return new Result<T>(value, true, messages ?? [], HttpStatusCode.NonAuthoritativeInformation);
} }
/// <summary> /// <summary>
/// Returns a result indicating the request was successful but there is no content to send in the response. /// Returns a result indicating the request was successful but there is no content to send in the response.
/// Corresponds to HTTP status code 204 No Content. /// Corresponds to HTTP status code 204 No Content.
/// </summary> /// </summary>
public static Result<T> NoContent(T? value, string? message = null) => public static Result<T> NoContent(T? value, params string[] messages) {
NoContent(value, messages: message != null ? [message] : null); return new Result<T>(value, true, [..messages], HttpStatusCode.NoContent);
/// <summary>
/// Returns a result indicating the request was successful but there is no content to send in the response.
/// Corresponds to HTTP status code 204 No Content.
/// </summary>
public static Result<T> NoContent(T? value, List<string>? messages = null) {
return new Result<T>(value, true, messages ?? [], HttpStatusCode.NoContent);
} }
/// <summary> /// <summary>
/// Returns a result indicating the request was successful, but the user-agent should reset the document view that caused the request. /// Returns a result indicating the request was successful, but the user-agent should reset the document view that caused the request.
/// Corresponds to HTTP status code 205 Reset Content. /// Corresponds to HTTP status code 205 Reset Content.
/// </summary> /// </summary>
public static Result<T> ResetContent(T? value, string? message = null) => public static Result<T> ResetContent(T? value, params string[] messages) {
ResetContent(value, messages: message != null ? [message] : null); return new Result<T>(value, true, [..messages], HttpStatusCode.ResetContent);
/// <summary>
/// Returns a result indicating the request was successful, but the user-agent should reset the document view that caused the request.
/// Corresponds to HTTP status code 205 Reset Content.
/// </summary>
public static Result<T> ResetContent(T? value, List<string>? messages = null) {
return new Result<T>(value, true, messages ?? [], HttpStatusCode.ResetContent);
} }
/// <summary> /// <summary>
/// Returns a result indicating the request was successful and the server is delivering only part of the resource due to a range header sent by the client. /// Returns a result indicating the request was successful and the server is delivering only part of the resource due to a range header sent by the client.
/// Corresponds to HTTP status code 206 Partial Content. /// Corresponds to HTTP status code 206 Partial Content.
/// </summary> /// </summary>
public static Result<T> PartialContent(T? value, string? message = null) => public static Result<T> PartialContent(T? value, params string[] messages) {
PartialContent(value, messages: message != null ? [message] : null); return new Result<T>(value, true, [..messages], HttpStatusCode.PartialContent);
/// <summary>
/// Returns a result indicating the request was successful and the server is delivering only part of the resource due to a range header sent by the client.
/// Corresponds to HTTP status code 206 Partial Content.
/// </summary>
public static Result<T> PartialContent(T? value, List<string>? messages = null) {
return new Result<T>(value, true, messages ?? [], HttpStatusCode.PartialContent);
} }
/// <summary> /// <summary>
/// Returns a result indicating the request was successful and the response contains multiple status codes, typically used for WebDAV. /// Returns a result indicating the request was successful and the response contains multiple status codes, typically used for WebDAV.
/// Corresponds to HTTP status code 207 Multi-Status. /// Corresponds to HTTP status code 207 Multi-Status.
/// </summary> /// </summary>
public static Result<T> MultiStatus(T? value, string? message = null) => public static Result<T> MultiStatus(T? value, params string[] messages) {
MultiStatus(value, messages: message != null ? [message] : null); return new Result<T>(value, true, [..messages], HttpStatusCode.MultiStatus);
/// <summary>
/// Returns a result indicating the request was successful and the response contains multiple status codes, typically used for WebDAV.
/// Corresponds to HTTP status code 207 Multi-Status.
/// </summary>
public static Result<T> MultiStatus(T? value, List<string>? messages = null) {
return new Result<T>(value, true, messages ?? [], HttpStatusCode.MultiStatus);
} }
/// <summary> /// <summary>
/// Returns a result indicating the request was successful and the information has already been reported in a previous response. /// Returns a result indicating the request was successful and the information has already been reported in a previous response.
/// Corresponds to HTTP status code 208 Already Reported. /// Corresponds to HTTP status code 208 Already Reported.
/// </summary> /// </summary>
public static Result<T> AlreadyReported(T? value, string? message = null) => public static Result<T> AlreadyReported(T? value, params string[] messages) {
AlreadyReported(value, messages: message != null ? [message] : null); return new Result<T>(value, true, [..messages], HttpStatusCode.AlreadyReported);
/// <summary>
/// Returns a result indicating the request was successful and the information has already been reported in a previous response.
/// Corresponds to HTTP status code 208 Already Reported.
/// </summary>
public static Result<T> AlreadyReported(T? value, List<string>? messages = null) {
return new Result<T>(value, true, messages ?? [], HttpStatusCode.AlreadyReported);
} }
/// <summary> /// <summary>
/// Returns a result indicating the request was successful and the server fulfilled the request for the resource using the delta encoding method. /// Returns a result indicating the request was successful and the server fulfilled the request for the resource using the delta encoding method.
/// Corresponds to HTTP status code 226 IM Used. /// Corresponds to HTTP status code 226 IM Used.
/// </summary> /// </summary>
public static Result<T> IMUsed(T? value, string? message = null) => public static Result<T> IMUsed(T? value, params string[] messages) {
IMUsed(value, messages: message != null ? [message] : null); return new Result<T>(value, true, [..messages], (HttpStatusCode)226); // 226 is the official status code for IM Used
/// <summary>
/// Returns a result indicating the request was successful and the server fulfilled the request for the resource using the delta encoding method.
/// Corresponds to HTTP status code 226 IM Used.
/// </summary>
public static Result<T> IMUsed(T? value, List<string>? messages = null) {
return new Result<T>(value, true, messages ?? [], (HttpStatusCode)226); // 226 is the official status code for IM Used
} }
} }