Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add params overload for Invalid factory method #152

Merged
merged 1 commit into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/Ardalis.Result/Result.Void.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,16 @@ public static Result ErrorWithCorrelationId(string correlationId, params string[
return new Result(ResultStatus.Invalid) { ValidationErrors = { validationError } };
}

/// <summary>
/// Represents validation errors that prevent the underlying service from completing.
/// </summary>
/// <param name="validationErrors">A list of validation errors encountered</param>
/// <returns>A Result</returns>
public new static Result Invalid(params ValidationError[] validationErrors)
{
return new Result(ResultStatus.Invalid) { ValidationErrors = new List<ValidationError>(validationErrors) };
}

/// <summary>
/// Represents validation errors that prevent the underlying service from completing.
/// </summary>
Expand Down Expand Up @@ -184,4 +194,4 @@ public static Result CriticalError(params string[] errorMessages)
return new Result(ResultStatus.CriticalError) { Errors = errorMessages };
}
}
}
}
10 changes: 10 additions & 0 deletions src/Ardalis.Result/Result.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,16 @@ public static Result<T> Invalid(ValidationError validationError)
return new Result<T>(ResultStatus.Invalid) { ValidationErrors = { validationError } };
}

/// <summary>
/// Represents validation errors that prevent the underlying service from completing.
/// </summary>
/// <param name="validationErrors">A list of validation errors encountered</param>
/// <returns>A Result<typeparamref name="T"/></returns>
public static Result<T> Invalid(params ValidationError[] validationErrors)
{
return new Result<T>(ResultStatus.Invalid) { ValidationErrors = new List<ValidationError>(validationErrors) };
}

/// <summary>
/// Represents validation errors that prevent the underlying service from completing.
/// </summary>
Expand Down
17 changes: 17 additions & 0 deletions src/Ardalis.Result/ValidationError.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,23 @@
{
public class ValidationError
{
public ValidationError()
{
}

public ValidationError(string errorMessage)
{
ErrorMessage = errorMessage;
}

public ValidationError(string identifier, string errorMessage, string errorCode, ValidationSeverity severity)
{
Identifier = identifier;
ErrorMessage = errorMessage;
ErrorCode = errorCode;
Severity = severity;
}

public string Identifier { get; set; }
public string ErrorMessage { get; set; }
public string ErrorCode { get; set; }
Expand Down