(feature): allow null message in success results

This commit is contained in:
Maksym Sadovnychyy 2024-09-28 12:26:59 +02:00
parent 77e1ec671d
commit a7d42f4d26

View File

@ -9,150 +9,150 @@ 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) => public static Result Ok(string? message) =>
Ok(new List<string> { message }); Ok(message != null ? [message] : null);
/// <summary> /// <summary>
/// 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(List<string> messages) { public static Result Ok(List<string>? messages) {
return new Result(true, messages, HttpStatusCode.OK); 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) => public static Result Created(string? message) =>
Created(new List<string> { message }); Created(message != null ? [message] : null);
/// <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(List<string> messages) { public static Result Created(List<string>? messages) {
return new Result(true, messages, HttpStatusCode.Created); 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) => public static Result Accepted(string? message) =>
Accepted(new List<string> { message }); Accepted(message != null ? [message] : null);
/// <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(List<string> messages) { public static Result Accepted(List<string>? messages) {
return new Result(true, messages, HttpStatusCode.Accepted); 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) => public static Result NonAuthoritativeInformation(string? message) =>
NonAuthoritativeInformation(new List<string> { message }); NonAuthoritativeInformation(message != null ? [message] : null);
/// <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(List<string> messages) { public static Result NonAuthoritativeInformation(List<string>? messages) {
return new Result(true, messages, HttpStatusCode.NonAuthoritativeInformation); 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) => public static Result NoContent(string? message) =>
ResetContent(new List<string> { message }); ResetContent(message != null ? [message] : null);
/// <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(List<string> messages) { public static Result NoContent(List<string>? messages) {
return new Result(true, messages, HttpStatusCode.NoContent); 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) => public static Result ResetContent(string? message) =>
ResetContent(new List<string> { message }); ResetContent(message != null ? [message] : null);
/// <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(List<string> messages) { public static Result ResetContent(List<string>? messages) {
return new Result(true, messages, HttpStatusCode.ResetContent); 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) => public static Result PartialContent(string? message) =>
PartialContent(new List<string> { message }); PartialContent(message != null ? [message] : null);
/// <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(List<string> messages) { public static Result PartialContent(List<string>? messages) {
return new Result(true, messages, HttpStatusCode.PartialContent); 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) => public static Result MultiStatus(string? message) =>
MultiStatus(new List<string> { message }); MultiStatus(message != null ? [message] : null);
/// <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(List<string> messages) { public static Result MultiStatus(List<string>? messages) {
return new Result(true, messages, HttpStatusCode.MultiStatus); 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) => public static Result AlreadyReported(string? message) =>
AlreadyReported(new List<string> { message }); AlreadyReported(message != null ? [message] : null);
/// <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(List<string> messages) { public static Result AlreadyReported(List<string>? messages) {
return new Result(true, messages, HttpStatusCode.AlreadyReported); 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) => public static Result IMUsed(string? message) =>
IMUsed(new List<string> { message }); IMUsed(message != null ? [message] : null);
/// <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(List<string> messages) { public static Result IMUsed(List<string>? messages) {
return new Result(true, messages, (HttpStatusCode)226); // 226 is the official status code for IM Used 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 +161,149 @@ 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) => public static Result<T> Ok(T? value, string? message) =>
Ok(value, new List<string> { message }); Ok(value, message != null ? [message] : null);
/// <summary> /// <summary>
/// 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, List<string> messages) { public static Result<T> Ok(T? value, List<string>? messages) {
return new Result<T>(value, true, messages, HttpStatusCode.OK); 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) => public static Result<T> Created(T? value, string? message) =>
Created(value, new List<string> { message }); Created(value, message != null ? [message] : null);
/// <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, List<string> messages) { public static Result<T> Created(T? value, List<string>? messages) {
return new Result<T>(value, true, messages, HttpStatusCode.Created); 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) => public static Result<T> Accepted(T? value, string? message) =>
Accepted(value, new List<string> { message }); Accepted(value, message != null ? [message] : null);
/// <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, List<string> messages) { public static Result<T> Accepted(T? value, List<string>? messages) {
return new Result<T>(value, true, messages, HttpStatusCode.Accepted); 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) => public static Result<T> NonAuthoritativeInformation(T? value, string? message) =>
NonAuthoritativeInformation(value, new List<string> { message }); NonAuthoritativeInformation(value, message != null ? [message] : null);
/// <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, List<string> messages) { public static Result<T> NonAuthoritativeInformation(T? value, List<string>? messages) {
return new Result<T>(value, true, messages, HttpStatusCode.NonAuthoritativeInformation); 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) => public static Result<T> NoContent(T? value, string? message) =>
NoContent(value, new List<string> { message }); NoContent(value, message != null ? [message] : null);
/// <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, List<string> messages) { public static Result<T> NoContent(T? value, List<string>? messages) {
return new Result<T>(value, true, messages, HttpStatusCode.NoContent); 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) => public static Result<T> ResetContent(T? value, string? message) =>
ResetContent(value, new List<string> { message }); ResetContent(value, message != null ? [message] : null);
/// <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, List<string> messages) { public static Result<T> ResetContent(T? value, List<string>? messages) {
return new Result<T>(value, true, messages, HttpStatusCode.ResetContent); 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) => public static Result<T> PartialContent(T? value, string? message) =>
PartialContent(value, new List<string> { message }); PartialContent(value, message != null ? [message] : null);
/// <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, List<string> messages) { public static Result<T> PartialContent(T? value, List<string>? messages) {
return new Result<T>(value, true, messages, HttpStatusCode.PartialContent); 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) => public static Result<T> MultiStatus(T? value, string? message) =>
MultiStatus(value, new List<string> { message }); MultiStatus(value, message != null ? [message] : null);
/// <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, List<string> messages) { public static Result<T> MultiStatus(T? value, List<string>? messages) {
return new Result<T>(value, true, messages, HttpStatusCode.MultiStatus); 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) => public static Result<T> AlreadyReported(T? value, string? message) =>
AlreadyReported(value, new List<string> { message }); AlreadyReported(value, message != null ? [message] : null);
/// <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, List<string> messages) { public static Result<T> AlreadyReported(T? value, List<string>? messages) {
return new Result<T>(value, true, messages, HttpStatusCode.AlreadyReported); 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) => public static Result<T> IMUsed(T? value, string? message) =>
IMUsed(value, new List<string> { message }); IMUsed(value, message != null ? [message] : null);
/// <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, List<string> messages) { public static Result<T> IMUsed(T? value, List<string>? messages) {
return new Result<T>(value, true, messages, (HttpStatusCode)226); // 226 is the official status code for IM Used return new Result<T>(value, true, messages ?? [], (HttpStatusCode)226); // 226 is the official status code for IM Used
} }
} }