diff --git a/src/Core/Result.Errors.cs b/src/Core/Result.Errors.cs index d2f08b1..c58c82f 100644 --- a/src/Core/Result.Errors.cs +++ b/src/Core/Result.Errors.cs @@ -2,6 +2,17 @@ public partial class Result { + private static Result CreateError( + string message, + ResultStatus status, + IEnumerable errors) => new() + { + IsSuccess = false, + Message = message, + Status = status, + Errors = errors + }; + /// public static Result Failure() => Failure(ResponseMessages.Failure); @@ -20,13 +31,8 @@ public static Result Failure(IEnumerable errors) /// /// A general description of the error. /// A collection of errors. - public static Result Failure(string message, IEnumerable errors) => new() - { - IsSuccess = false, - Message = message, - Status = ResultStatus.Failure, - Errors = errors - }; + public static Result Failure(string message, IEnumerable errors) + => CreateError(message, ResultStatus.Failure, errors); /// public static Result Invalid() @@ -46,13 +52,8 @@ public static Result Invalid(IEnumerable errors) /// /// A general description of the error. /// A collection of errors. - public static Result Invalid(string message, IEnumerable errors) => new() - { - IsSuccess = false, - Message = message, - Status = ResultStatus.Invalid, - Errors = errors - }; + public static Result Invalid(string message, IEnumerable errors) + => CreateError(message, ResultStatus.Invalid, errors); /// public static Result NotFound() @@ -72,13 +73,8 @@ public static Result NotFound(IEnumerable errors) /// /// A general description of the error. /// A collection of errors. - public static Result NotFound(string message, IEnumerable errors) => new() - { - IsSuccess = false, - Message = message, - Status = ResultStatus.NotFound, - Errors = errors - }; + public static Result NotFound(string message, IEnumerable errors) + => CreateError(message, ResultStatus.NotFound, errors); /// public static Result Unauthorized() @@ -101,13 +97,8 @@ public static Result Unauthorized(IEnumerable errors) /// /// A general description of the error. /// A collection of errors. - public static Result Unauthorized(string message, IEnumerable errors) => new() - { - IsSuccess = false, - Message = message, - Status = ResultStatus.Unauthorized, - Errors = errors - }; + public static Result Unauthorized(string message, IEnumerable errors) + => CreateError(message, ResultStatus.Unauthorized, errors); /// public static Result Conflict() @@ -127,13 +118,8 @@ public static Result Conflict(IEnumerable errors) /// /// A general description of the error. /// A collection of errors. - public static Result Conflict(string message, IEnumerable errors) => new() - { - IsSuccess = false, - Message = message, - Status = ResultStatus.Conflict, - Errors = errors - }; + public static Result Conflict(string message, IEnumerable errors) + => CreateError(message, ResultStatus.Conflict, errors); /// public static Result CriticalError() @@ -156,13 +142,8 @@ public static Result CriticalError(IEnumerable errors) /// /// A general description of the error. /// A collection of errors. - public static Result CriticalError(string message, IEnumerable errors) => new() - { - IsSuccess = false, - Message = message, - Status = ResultStatus.CriticalError, - Errors = errors - }; + public static Result CriticalError(string message, IEnumerable errors) + => CreateError(message, ResultStatus.CriticalError, errors); /// public static Result Forbidden() @@ -182,11 +163,6 @@ public static Result Forbidden(IEnumerable errors) /// /// A general description of the error. /// A collection of errors. - public static Result Forbidden(string message, IEnumerable errors) => new() - { - IsSuccess = false, - Message = message, - Status = ResultStatus.Forbidden, - Errors = errors - }; + public static Result Forbidden(string message, IEnumerable errors) + => CreateError(message, ResultStatus.Forbidden, errors); }