diff --git a/src/Ardalis.Result.AspNetCore/ActionResultExtensions.cs b/src/Ardalis.Result.AspNetCore/ActionResultExtensions.cs
index 35acaab..77e43b8 100644
--- a/src/Ardalis.Result.AspNetCore/ActionResultExtensions.cs
+++ b/src/Ardalis.Result.AspNetCore/ActionResultExtensions.cs
@@ -17,9 +17,7 @@ public static partial class ResultExtensions
/// The Result to convert to an ActionResult
///
public static ActionResult ToActionResult(this Result result, ControllerBase controller)
- {
- return controller.ToActionResult((IResult)result);
- }
+ => controller.ToActionResult((IResult)result);
///
/// Convert a to a
@@ -28,9 +26,7 @@ public static ActionResult ToActionResult(this Result result, Controlle
/// The Result to convert to an ActionResult
///
public static ActionResult ToActionResult(this Result result, ControllerBase controller)
- {
- return controller.ToActionResult((IResult)result);
- }
+ => controller.ToActionResult((IResult)result);
///
/// Convert a to a
@@ -39,11 +35,8 @@ public static ActionResult ToActionResult(this Result result, ControllerBase con
/// The controller this is called from
/// The Result to convert to an ActionResult
///
- public static ActionResult ToActionResult(this ControllerBase controller,
- Result result)
- {
- return controller.ToActionResult((IResult)result);
- }
+ public static ActionResult ToActionResult(this ControllerBase controller, Result result)
+ => controller.ToActionResult((IResult)result);
///
/// Convert a to a
@@ -51,18 +44,15 @@ public static ActionResult ToActionResult(this ControllerBase controller,
/// The controller this is called from
/// The Result to convert to an ActionResult
///
- public static ActionResult ToActionResult(this ControllerBase controller,
- Result result)
- {
- return controller.ToActionResult((IResult)result);
- }
+ public static ActionResult ToActionResult(this ControllerBase controller, Result result)
+ => controller.ToActionResult((IResult)result);
internal static ActionResult ToActionResult(this ControllerBase controller, IResult result)
{
var actionProps = controller.ControllerContext.ActionDescriptor.Properties;
- var resultStatusMap = actionProps.ContainsKey(ResultConvention.RESULT_STATUS_MAP_PROP)
- ?(actionProps[ResultConvention.RESULT_STATUS_MAP_PROP] as ResultStatusMap)
+ var resultStatusMap = actionProps.ContainsKey(ResultConvention.RESULT_STATUS_MAP_PROP)
+ ? (actionProps[ResultConvention.RESULT_STATUS_MAP_PROP] as ResultStatusMap)
: new ResultStatusMap().AddDefaultMap();
var resultStatusOptions = resultStatusMap[result.Status];
diff --git a/src/Ardalis.Result.AspNetCore/Exceptions/UnexpectedFailureResultException.cs b/src/Ardalis.Result.AspNetCore/Exceptions/UnexpectedFailureResultException.cs
index ec24fe7..74775ef 100644
--- a/src/Ardalis.Result.AspNetCore/Exceptions/UnexpectedFailureResultException.cs
+++ b/src/Ardalis.Result.AspNetCore/Exceptions/UnexpectedFailureResultException.cs
@@ -3,18 +3,11 @@
namespace Ardalis.Result.AspNetCore.Exceptions
{
- internal class UnexpectedFailureResultsException : Exception
+ internal class UnexpectedFailureResultsException(IEnumerable statuses) : Exception
{
- public UnexpectedFailureResultsException(IEnumerable statuses)
- {
- UnexpectedStatuses = statuses;
- }
-
- public IEnumerable UnexpectedStatuses { get; }
+ public IEnumerable UnexpectedStatuses { get; } = statuses;
public override string ToString()
- {
- return $"ActionModel has [{nameof(ExpectedFailuresAttribute)}] with result statuses which are not configured in ResultConvention.";
- }
+ => $"ActionModel has [{nameof(ExpectedFailuresAttribute)}] with result statuses which are not configured in ResultConvention.";
}
}
diff --git a/src/Ardalis.Result.AspNetCore/ExpectedFailuresAttribute.cs b/src/Ardalis.Result.AspNetCore/ExpectedFailuresAttribute.cs
index 648c349..f62f75a 100644
--- a/src/Ardalis.Result.AspNetCore/ExpectedFailuresAttribute.cs
+++ b/src/Ardalis.Result.AspNetCore/ExpectedFailuresAttribute.cs
@@ -4,13 +4,8 @@
namespace Ardalis.Result.AspNetCore
{
[AttributeUsage(AttributeTargets.Method)]
- public class ExpectedFailuresAttribute : Attribute
+ public class ExpectedFailuresAttribute(params ResultStatus[] resultStatuses) : Attribute
{
- public ExpectedFailuresAttribute(params ResultStatus[] resultStatuses)
- {
- ResultStatuses = resultStatuses;
- }
-
- public IEnumerable ResultStatuses { get; }
+ public IEnumerable ResultStatuses { get; } = resultStatuses;
}
}
diff --git a/src/Ardalis.Result.AspNetCore/MinimalApiResultExtensions.cs b/src/Ardalis.Result.AspNetCore/MinimalApiResultExtensions.cs
index efbe73b..cd97e70 100644
--- a/src/Ardalis.Result.AspNetCore/MinimalApiResultExtensions.cs
+++ b/src/Ardalis.Result.AspNetCore/MinimalApiResultExtensions.cs
@@ -16,20 +16,14 @@ public static partial class ResultExtensions
/// The value being returned
/// The Ardalis.Result to convert to an Microsoft.AspNetCore.Http.IResult
///
- public static Microsoft.AspNetCore.Http.IResult ToMinimalApiResult(this Result result)
- {
- return ToMinimalApiResult((IResult)result);
- }
+ public static Microsoft.AspNetCore.Http.IResult ToMinimalApiResult(this Result result) => ToMinimalApiResult((IResult)result);
///
/// Convert a to an instance of
///
/// The Ardalis.Result to convert to an Microsoft.AspNetCore.Http.IResult
///
- public static Microsoft.AspNetCore.Http.IResult ToMinimalApiResult(this Result result)
- {
- return ToMinimalApiResult((IResult)result);
- }
+ public static Microsoft.AspNetCore.Http.IResult ToMinimalApiResult(this Result result) => ToMinimalApiResult((IResult)result);
internal static Microsoft.AspNetCore.Http.IResult ToMinimalApiResult(this IResult result) =>
result.Status switch
diff --git a/src/Ardalis.Result.AspNetCore/ResultConvention.cs b/src/Ardalis.Result.AspNetCore/ResultConvention.cs
index c6dc81d..d0bbadc 100644
--- a/src/Ardalis.Result.AspNetCore/ResultConvention.cs
+++ b/src/Ardalis.Result.AspNetCore/ResultConvention.cs
@@ -20,10 +20,7 @@ internal class ResultConvention : IActionModelConvention
private readonly ResultStatusMap _map;
- internal ResultConvention(ResultStatusMap map)
- {
- _map = map;
- }
+ internal ResultConvention(ResultStatusMap map) => _map = map;
public void Apply(ActionModel action)
{
diff --git a/src/Ardalis.Result.AspNetCore/ResultStatusMap.cs b/src/Ardalis.Result.AspNetCore/ResultStatusMap.cs
index 99d8754..624392a 100644
--- a/src/Ardalis.Result.AspNetCore/ResultStatusMap.cs
+++ b/src/Ardalis.Result.AspNetCore/ResultStatusMap.cs
@@ -24,8 +24,8 @@ internal ResultStatusMap()
/// Adds default mapping for all known es to s
///
public ResultStatusMap AddDefaultMap()
- {
- return For(ResultStatus.Ok, HttpStatusCode.OK)
+
+ => For(ResultStatus.Ok, HttpStatusCode.OK)
.For(ResultStatus.Created, HttpStatusCode.Created)
.For(ResultStatus.Error, (HttpStatusCode)422, resultStatusOptions => resultStatusOptions
.With(UnprocessableEntity))
@@ -44,7 +44,6 @@ public ResultStatusMap AddDefaultMap()
resultStatusOptions
.With(UnavailableEntity))
.For(ResultStatus.NoContent, HttpStatusCode.NoContent);
- }
///
/// Maps to .
@@ -88,10 +87,7 @@ public ResultStatusMap Remove(ResultStatus status)
///
///
///
- public bool ContainsKey(ResultStatus status)
- {
- return _map.ContainsKey(status);
- }
+ public bool ContainsKey(ResultStatus status) => _map.ContainsKey(status);
internal ResultStatusOptions this[ResultStatus status]
{
@@ -138,7 +134,7 @@ private static ProblemDetails NotFoundEntity(ControllerBase controller, IResult
Detail = result.Errors.Any() ? details.ToString() : null
};
}
-
+
private static ProblemDetails ConflictEntity(ControllerBase controller, IResult result)
{
var details = new StringBuilder("Next error(s) occurred:");
diff --git a/src/Ardalis.Result/PagedInfo.cs b/src/Ardalis.Result/PagedInfo.cs
index fcde565..af80dfb 100644
--- a/src/Ardalis.Result/PagedInfo.cs
+++ b/src/Ardalis.Result/PagedInfo.cs
@@ -2,25 +2,16 @@
namespace Ardalis.Result
{
- public class PagedInfo
+ public class PagedInfo(long pageNumber, long pageSize, long totalPages, long totalRecords)
{
-
- public PagedInfo(long pageNumber, long pageSize, long totalPages, long totalRecords)
- {
- PageNumber = pageNumber;
- PageSize = pageSize;
- TotalPages = totalPages;
- TotalRecords = totalRecords;
- }
-
- [JsonInclude]
- public long PageNumber { get; private set; }
- [JsonInclude]
- public long PageSize { get; private set; }
- [JsonInclude]
- public long TotalPages { get; private set; }
- [JsonInclude]
- public long TotalRecords { get; private set; }
+ [JsonInclude]
+ public long PageNumber { get; private set; } = pageNumber;
+ [JsonInclude]
+ public long PageSize { get; private set; } = pageSize;
+ [JsonInclude]
+ public long TotalPages { get; private set; } = totalPages;
+ [JsonInclude]
+ public long TotalRecords { get; private set; } = totalRecords;
public PagedInfo SetPageNumber(long pageNumber)
{
diff --git a/src/Ardalis.Result/PagedResult.cs b/src/Ardalis.Result/PagedResult.cs
index 971ee91..efaa108 100644
--- a/src/Ardalis.Result/PagedResult.cs
+++ b/src/Ardalis.Result/PagedResult.cs
@@ -2,14 +2,9 @@
namespace Ardalis.Result
{
- public class PagedResult : Result
+ public class PagedResult(PagedInfo pagedInfo, T value) : Result(value)
{
- public PagedResult(PagedInfo pagedInfo, T value) : base(value)
- {
- PagedInfo = pagedInfo;
- }
-
- [JsonInclude]
- public PagedInfo PagedInfo { get; init; }
+ [JsonInclude]
+ public PagedInfo PagedInfo { get; init; } = pagedInfo;
}
}
diff --git a/src/Ardalis.Result/Result.Void.cs b/src/Ardalis.Result/Result.Void.cs
index 55f5c74..21d58f4 100644
--- a/src/Ardalis.Result/Result.Void.cs
+++ b/src/Ardalis.Result/Result.Void.cs
@@ -12,30 +12,21 @@ protected internal Result(ResultStatus status) : base(status) { }
/// Represents a successful operation without return type
///
/// A Result
- public static Result Success()
- {
- return new Result();
- }
+ public static Result Success() => new();
///
/// Represents a successful operation without return type
///
/// Sets the SuccessMessage property
/// A Result
- public static Result SuccessWithMessage(string successMessage)
- {
- return new Result { SuccessMessage = successMessage };
- }
+ public static Result SuccessWithMessage(string successMessage) => new() { SuccessMessage = successMessage };
///
/// Represents a successful operation and accepts a values as the result of the operation
///
/// Sets the Value property
/// A Result
- public static Result Success(T value)
- {
- return new Result(value);
- }
+ public static Result Success(T value) => new(value);
///
/// Represents a successful operation and accepts a values as the result of the operation
@@ -44,10 +35,7 @@ public static Result Success(T value)
/// Sets the Value property
/// Sets the SuccessMessage property
/// A Result
- public static Result Success(T value, string successMessage)
- {
- return new Result(value, successMessage);
- }
+ public static Result Success(T value, string successMessage) => new(value, successMessage);
///
/// Represents a successful operation that resulted in the creation of a new resource.
@@ -79,14 +67,11 @@ public static Result Created(T value, string location)
///
/// An optional instance of ErrorList with list of string error messages and CorrelationId.
/// A Result
- public new static Result Error(ErrorList error = null)
+ public new static Result Error(ErrorList error = null) => new(ResultStatus.Error)
{
- return new Result(ResultStatus.Error)
- {
- CorrelationId = error?.CorrelationId ?? string.Empty,
- Errors = error?.ErrorMessages ?? []
- };
- }
+ CorrelationId = error?.CorrelationId ?? string.Empty,
+ Errors = error?.ErrorMessages ?? []
+ };
///
/// Represents an error that occurred during the execution of the service.
@@ -94,11 +79,7 @@ public static Result Created(T value, string location)
///
///
/// A Result
- public new static Result Error(string errorMessage)
- {
- return new Result(ResultStatus.Error) { Errors = new[] { errorMessage } };
- }
-
+ public new static Result Error(string errorMessage) => new(ResultStatus.Error) { Errors = new[] { errorMessage } };
///
/// Represents the validation error that prevents the underlying service from completing.
@@ -106,9 +87,7 @@ public static Result Created(T value, string location)
/// The validation error encountered
/// A Result
public new static Result Invalid(ValidationError validationError)
- {
- return new Result(ResultStatus.Invalid) { ValidationErrors = [validationError] };
- }
+ => new(ResultStatus.Invalid) { ValidationErrors = [validationError] };
///
/// Represents validation errors that prevent the underlying service from completing.
@@ -116,9 +95,7 @@ public static Result Created(T value, string location)
/// A list of validation errors encountered
/// A Result
public new static Result Invalid(params ValidationError[] validationErrors)
- {
- return new Result(ResultStatus.Invalid) { ValidationErrors = new List(validationErrors) };
- }
+ => new(ResultStatus.Invalid) { ValidationErrors = new List(validationErrors) };
///
/// Represents validation errors that prevent the underlying service from completing.
@@ -126,18 +103,13 @@ public static Result Created(T value, string location)
/// A list of validation errors encountered
/// A Result
public new static Result Invalid(IEnumerable validationErrors)
- {
- return new Result(ResultStatus.Invalid) { ValidationErrors = validationErrors };
- }
+ => new(ResultStatus.Invalid) { ValidationErrors = validationErrors };
///
/// Represents the situation where a service was unable to find a requested resource.
///
/// A Result
- public new static Result NotFound()
- {
- return new Result(ResultStatus.NotFound);
- }
+ public new static Result NotFound() => new Result(ResultStatus.NotFound);
///
/// Represents the situation where a service was unable to find a requested resource.
@@ -145,20 +117,14 @@ public static Result Created(T value, string location)
///
/// A list of string error messages.
/// A Result
- public new static Result NotFound(params string[] errorMessages)
- {
- return new Result(ResultStatus.NotFound) { Errors = errorMessages };
- }
+ public new static Result NotFound(params string[] errorMessages) => new(ResultStatus.NotFound) { Errors = errorMessages };
///
/// The parameters to the call were correct, but the user does not have permission to perform some action.
/// See also HTTP 403 Forbidden: https://en.wikipedia.org/wiki/List_of_HTTP_status_codes#4xx_client_errors
///
/// A Result
- public new static Result Forbidden()
- {
- return new Result(ResultStatus.Forbidden);
- }
+ public new static Result Forbidden() => new(ResultStatus.Forbidden);
///
/// The parameters to the call were correct, but the user does not have permission to perform some action.
@@ -166,20 +132,14 @@ public static Result Created(T value, string location)
///
/// A list of string error messages.
/// A Result
- public new static Result Forbidden(params string[] errorMessages)
- {
- return new Result(ResultStatus.Forbidden) { Errors = errorMessages };
- }
+ public new static Result Forbidden(params string[] errorMessages) => new(ResultStatus.Forbidden) { Errors = errorMessages };
///
/// This is similar to Forbidden, but should be used when the user has not authenticated or has attempted to authenticate but failed.
/// See also HTTP 401 Unauthorized: https://en.wikipedia.org/wiki/List_of_HTTP_status_codes#4xx_client_errors
///
/// A Result
- public new static Result Unauthorized()
- {
- return new Result(ResultStatus.Unauthorized);
- }
+ public new static Result Unauthorized() => new(ResultStatus.Unauthorized);
///
/// This is similar to Forbidden, but should be used when the user has not authenticated or has attempted to authenticate but failed.
@@ -187,10 +147,7 @@ public static Result Created(T value, string location)
///
/// A list of string error messages.
/// A Result
- public new static Result Unauthorized(params string[] errorMessages)
- {
- return new Result(ResultStatus.Unauthorized) { Errors = errorMessages };
- }
+ public new static Result Unauthorized(params string[] errorMessages) => new(ResultStatus.Unauthorized) { Errors = errorMessages };
///
/// Represents a situation where a service is in conflict due to the current state of a resource,
@@ -198,10 +155,7 @@ public static Result Created(T value, string location)
/// See also HTTP 409 Conflict: https://en.wikipedia.org/wiki/List_of_HTTP_status_codes#4xx_client_errors
///
/// A Result
- public new static Result Conflict()
- {
- return new Result(ResultStatus.Conflict);
- }
+ public new static Result Conflict() => new(ResultStatus.Conflict);
///
/// Represents a situation where a service is in conflict due to the current state of a resource,
@@ -211,10 +165,7 @@ public static Result Created(T value, string location)
///
/// A list of string error messages.
/// A Result
- public new static Result Conflict(params string[] errorMessages)
- {
- return new Result(ResultStatus.Conflict) { Errors = errorMessages };
- }
+ public new static Result Conflict(params string[] errorMessages) => new(ResultStatus.Conflict) { Errors = errorMessages };
///
/// Represents a situation where a service is unavailable, such as when the underlying data store is unavailable.
@@ -223,11 +174,8 @@ public static Result Created(T value, string location)
///
/// A list of string error messages
///
- public new static Result Unavailable(params string[] errorMessages)
- {
- return new Result(ResultStatus.Unavailable) { Errors = errorMessages };
- }
-
+ public new static Result Unavailable(params string[] errorMessages) => new(ResultStatus.Unavailable) { Errors = errorMessages };
+
///
/// Represents a critical error that occurred during the execution of the service.
/// Everything provided by the user was valid, but the service was unable to complete due to an exception.
@@ -235,18 +183,12 @@ public static Result Created(T value, string location)
///
/// A list of string error messages.
/// A Result
- public new static Result CriticalError(params string[] errorMessages)
- {
- return new Result(ResultStatus.CriticalError) { Errors = errorMessages };
- }
+ public new static Result CriticalError(params string[] errorMessages) => new(ResultStatus.CriticalError) { Errors = errorMessages };
///
/// Represents a situation where the server has successfully fulfilled the request, but there is no content to send back in the response body.
///
/// A Result object
- public new static Result NoContent()
- {
- return new Result(ResultStatus.NoContent);
- }
+ public new static Result NoContent() => new(ResultStatus.NoContent);
}
}
diff --git a/src/Ardalis.Result/Result.cs b/src/Ardalis.Result/Result.cs
index 79b2569..f00d497 100644
--- a/src/Ardalis.Result/Result.cs
+++ b/src/Ardalis.Result/Result.cs
@@ -9,25 +9,16 @@ public class Result : IResult
{
protected Result() { }
- public Result(T value)
- {
- Value = value;
- }
+ public Result(T value) => Value = value;
- protected internal Result(T value, string successMessage) : this(value)
- {
- SuccessMessage = successMessage;
- }
+ protected internal Result(T value, string successMessage) : this(value) => SuccessMessage = successMessage;
- protected Result(ResultStatus status)
- {
- Status = status;
- }
+ protected Result(ResultStatus status) => Status = status;
public static implicit operator T(Result result) => result.Value;
public static implicit operator Result(T value) => new Result(value);
- public static implicit operator Result(Result result) => new Result(default(T))
+ public static implicit operator Result(Result result) => new(default(T))
{
Status = result.Status,
Errors = result.Errors,
@@ -36,35 +27,32 @@ protected Result(ResultStatus status)
ValidationErrors = result.ValidationErrors,
};
- [JsonInclude]
+ [JsonInclude]
public T Value { get; init; }
[JsonIgnore]
public Type ValueType => typeof(T);
- [JsonInclude]
+ [JsonInclude]
public ResultStatus Status { get; protected set; } = ResultStatus.Ok;
public bool IsSuccess => Status is ResultStatus.Ok or ResultStatus.NoContent or ResultStatus.Created;
- [JsonInclude]
+ [JsonInclude]
public string SuccessMessage { get; protected set; } = string.Empty;
- [JsonInclude]
+ [JsonInclude]
public string CorrelationId { get; protected set; } = string.Empty;
- [JsonInclude]
+ [JsonInclude]
public string Location { get; protected set; } = string.Empty;
- [JsonInclude]
+ [JsonInclude]
public IEnumerable Errors { get; protected set; } = [];
- [JsonInclude]
+ [JsonInclude]
public IEnumerable ValidationErrors { get; protected set; } = [];
///
/// Returns the current value.
///
///
- public object GetValue()
- {
- return this.Value;
- }
+ public object GetValue() => this.Value;
///
/// Converts PagedInfo into a PagedResult
@@ -90,10 +78,7 @@ public PagedResult ToPagedResult(PagedInfo pagedInfo)
///
/// Sets the Value property
/// A Result
- public static Result Success(T value)
- {
- return new Result(value);
- }
+ public static Result Success(T value) => new(value);
///
/// Represents a successful operation and accepts a values as the result of the operation
@@ -102,20 +87,14 @@ public static Result Success(T value)
/// Sets the Value property
/// Sets the SuccessMessage property
/// A Result
- public static Result Success(T value, string successMessage)
- {
- return new Result(value, successMessage);
- }
-
+ public static Result Success(T value, string successMessage) => new(value, successMessage);
+
///
/// Represents a successful operation that resulted in the creation of a new resource.
///
/// The type of the resource created.
/// A Result with status Created.
- public static Result Created(T value)
- {
- return new Result(ResultStatus.Created) { Value = value };
- }
+ public static Result Created(T value) => new(ResultStatus.Created) { Value = value };
///
/// Represents a successful operation that resulted in the creation of a new resource.
@@ -125,10 +104,7 @@ public static Result Created(T value)
/// The value of the resource created.
/// The URL indicating where the newly created resource can be accessed.
/// A Result with status Created.
- public static Result Created(T value, string location)
- {
- return new Result(ResultStatus.Created) { Value = value, Location = location };
- }
+ public static Result Created(T value, string location) => new(ResultStatus.Created) { Value = value, Location = location };
///
/// Represents an error that occurred during the execution of the service.
@@ -136,10 +112,7 @@ public static Result Created(T value, string location)
///
///
///
- public static Result Error(string errorMessage)
- {
- return new Result(ResultStatus.Error) { Errors = new[] { errorMessage } };
- }
+ public static Result Error(string errorMessage) => new(ResultStatus.Error) { Errors = new[] { errorMessage } };
///
/// Represents an error that occurred during the execution of the service.
@@ -147,14 +120,11 @@ public static Result Error(string errorMessage)
///
/// An optional instance of ErrorList with list of string error messages and CorrelationId.
/// A Result
- public static Result Error(ErrorList error = null)
+ public static Result Error(ErrorList error = null) => new(ResultStatus.Error)
{
- return new Result(ResultStatus.Error)
- {
- CorrelationId = error?.CorrelationId ?? string.Empty,
- Errors = error?.ErrorMessages ?? []
- };
- }
+ CorrelationId = error?.CorrelationId ?? string.Empty,
+ Errors = error?.ErrorMessages ?? []
+ };
///
/// Represents a validation error that prevents the underlying service from completing.
@@ -162,20 +132,16 @@ public static Result Error(ErrorList error = null)
/// The validation error encountered
/// A Result
public static Result Invalid(ValidationError validationError)
- {
- return new Result(ResultStatus.Invalid) { ValidationErrors = [validationError] };
- }
+ => new(ResultStatus.Invalid) { ValidationErrors = [validationError] };
///
/// Represents validation errors that prevent the underlying service from completing.
///
/// A list of validation errors encountered
/// A Result
- public static Result Invalid(params ValidationError[] validationErrors)
- {
- return new Result(ResultStatus.Invalid)
- { ValidationErrors = new List(validationErrors) };
- }
+ public static Result Invalid(params ValidationError[] validationErrors) =>
+ new(ResultStatus.Invalid)
+ { ValidationErrors = new List(validationErrors) };
///
/// Represents validation errors that prevent the underlying service from completing.
@@ -183,18 +149,13 @@ public static Result Invalid(params ValidationError[] validationErrors)
/// A list of validation errors encountered
/// A Result
public static Result Invalid(IEnumerable validationErrors)
- {
- return new Result(ResultStatus.Invalid) { ValidationErrors = validationErrors };
- }
+ => new(ResultStatus.Invalid) { ValidationErrors = validationErrors };
///
/// Represents the situation where a service was unable to find a requested resource.
///
/// A Result
- public static Result NotFound()
- {
- return new Result(ResultStatus.NotFound);
- }
+ public static Result NotFound() => new(ResultStatus.NotFound);
///
/// Represents the situation where a service was unable to find a requested resource.
@@ -202,20 +163,14 @@ public static Result NotFound()
///
/// A list of string error messages.
/// A Result
- public static Result NotFound(params string[] errorMessages)
- {
- return new Result(ResultStatus.NotFound) { Errors = errorMessages };
- }
+ public static Result NotFound(params string[] errorMessages) => new(ResultStatus.NotFound) { Errors = errorMessages };
///
/// The parameters to the call were correct, but the user does not have permission to perform some action.
/// See also HTTP 403 Forbidden: https://en.wikipedia.org/wiki/List_of_HTTP_status_codes#4xx_client_errors
///
/// A Result
- public static Result Forbidden()
- {
- return new Result(ResultStatus.Forbidden);
- }
+ public static Result Forbidden() => new(ResultStatus.Forbidden);
///
/// The parameters to the call were correct, but the user does not have permission to perform some action.
@@ -223,20 +178,14 @@ public static Result Forbidden()
///
/// A list of string error messages.
/// A Result
- public static Result Forbidden(params string[] errorMessages)
- {
- return new Result(ResultStatus.Forbidden) { Errors = errorMessages };
- }
+ public static Result Forbidden(params string[] errorMessages) => new(ResultStatus.Forbidden) { Errors = errorMessages };
///
/// This is similar to Forbidden, but should be used when the user has not authenticated or has attempted to authenticate but failed.
/// See also HTTP 401 Unauthorized: https://en.wikipedia.org/wiki/List_of_HTTP_status_codes#4xx_client_errors
///
/// A Result
- public static Result Unauthorized()
- {
- return new Result(ResultStatus.Unauthorized);
- }
+ public static Result Unauthorized() => new(ResultStatus.Unauthorized);
///
/// This is similar to Forbidden, but should be used when the user has not authenticated or has attempted to authenticate but failed.
@@ -244,10 +193,7 @@ public static Result Unauthorized()
///
/// A list of string error messages.
/// A Result
- public static Result Unauthorized(params string[] errorMessages)
- {
- return new Result(ResultStatus.Unauthorized) { Errors = errorMessages };
- }
+ public static Result Unauthorized(params string[] errorMessages) => new(ResultStatus.Unauthorized) { Errors = errorMessages };
///
/// Represents a situation where a service is in conflict due to the current state of a resource,
@@ -255,11 +201,8 @@ public static Result Unauthorized(params string[] errorMessages)
/// See also HTTP 409 Conflict: https://en.wikipedia.org/wiki/List_of_HTTP_status_codes#4xx_client_errors
///
/// A Result
- public static Result Conflict()
- {
- return new Result(ResultStatus.Conflict);
- }
-
+ public static Result Conflict() => new(ResultStatus.Conflict);
+
///
/// Represents a situation where a service is in conflict due to the current state of a resource,
/// such as an edit conflict between multiple concurrent updates.
@@ -268,11 +211,8 @@ public static Result Conflict()
///
/// A list of string error messages.
/// A Result
- public static Result Conflict(params string[] errorMessages)
- {
- return new Result(ResultStatus.Conflict) { Errors = errorMessages };
- }
-
+ public static Result Conflict(params string[] errorMessages) => new(ResultStatus.Conflict) { Errors = errorMessages };
+
///
/// Represents a critical error that occurred during the execution of the service.
/// Everything provided by the user was valid, but the service was unable to complete due to an exception.
@@ -280,10 +220,7 @@ public static Result Conflict(params string[] errorMessages)
///
/// A list of string error messages.
/// A Result
- public static Result CriticalError(params string[] errorMessages)
- {
- return new Result(ResultStatus.CriticalError) { Errors = errorMessages };
- }
+ public static Result CriticalError(params string[] errorMessages) => new(ResultStatus.CriticalError) { Errors = errorMessages };
///
/// Represents a situation where a service is unavailable, such as when the underlying data store is unavailable.
@@ -292,19 +229,13 @@ public static Result CriticalError(params string[] errorMessages)
///
/// A list of string error messages
///
- public static Result Unavailable(params string[] errorMessages)
- {
- return new Result(ResultStatus.Unavailable) { Errors = errorMessages};
- }
+ public static Result Unavailable(params string[] errorMessages) => new(ResultStatus.Unavailable) { Errors = errorMessages };
///
/// Represents a situation where the server has successfully fulfilled the request, but there is no content to send back in the response body.
///
/// The type parameter representing the expected response data.
/// A Result object
- public static Result NoContent()
- {
- return new Result(ResultStatus.NoContent);
- }
+ public static Result NoContent() => new(ResultStatus.NoContent);
}
}
diff --git a/src/Ardalis.Result/ValidationError.cs b/src/Ardalis.Result/ValidationError.cs
index 63485b7..4e37919 100644
--- a/src/Ardalis.Result/ValidationError.cs
+++ b/src/Ardalis.Result/ValidationError.cs
@@ -6,10 +6,7 @@ public ValidationError()
{
}
- public ValidationError(string errorMessage)
- {
- ErrorMessage = errorMessage;
- }
+ public ValidationError(string errorMessage) => ErrorMessage = errorMessage;
public ValidationError(string identifier, string errorMessage, string errorCode, ValidationSeverity severity)
{
diff --git a/src/Ardalis.Result/ValidationSeverity.cs b/src/Ardalis.Result/ValidationSeverity.cs
index c2b2bc2..a3dfbe3 100644
--- a/src/Ardalis.Result/ValidationSeverity.cs
+++ b/src/Ardalis.Result/ValidationSeverity.cs
@@ -2,8 +2,8 @@
{
public enum ValidationSeverity
{
- Error = 0,
- Warning = 1,
- Info = 2
+ Error,
+ Warning,
+ Info
}
}