| | | 1 | | namespace ZhEaIsNsAaBn.Utilities.ValidationResponses; |
| | | 2 | | |
| | | 3 | | /// <summary> |
| | | 4 | | /// Represents a validation response that contains validation errors and provides validation status. |
| | | 5 | | /// Supports implicit conversion from various error types for convenient usage. |
| | | 6 | | /// </summary> |
| | | 7 | | public class ValidationResponse |
| | | 8 | | { |
| | | 9 | | /// <summary> |
| | | 10 | | /// Gets or sets the list of validation errors. |
| | | 11 | | /// </summary> |
| | | 12 | | /// <value>The validation errors. Empty when the row is valid; never <see langword="null"/>.</value> |
| | | 13 | | public List<ColumnValidationError> Errors { get; set; } = []; |
| | | 14 | | |
| | | 15 | | /// <summary> |
| | | 16 | | /// Gets a value indicating whether the validation is successful (no errors). |
| | | 17 | | /// </summary> |
| | | 18 | | /// <value><c>true</c> if there are no validation errors; otherwise, <c>false</c>.</value> |
| | 30 | 19 | | public bool IsValid => Errors.Count == 0; |
| | | 20 | | |
| | | 21 | | /// <summary> |
| | | 22 | | /// Implicitly converts a list of validation errors to a <see cref="ValidationResponse" />. |
| | | 23 | | /// </summary> |
| | | 24 | | /// <param name="errors">The list of validation errors to convert.</param> |
| | | 25 | | /// <returns>A new <see cref="ValidationResponse" /> instance containing the specified errors.</returns> |
| | | 26 | | public static implicit operator ValidationResponse( List<ColumnValidationError> errors ) => |
| | 6 | 27 | | new() |
| | 6 | 28 | | { |
| | 6 | 29 | | Errors = errors |
| | 6 | 30 | | }; |
| | | 31 | | |
| | | 32 | | /// <summary> |
| | | 33 | | /// Implicitly converts an array of validation errors to a <see cref="ValidationResponse" />. |
| | | 34 | | /// </summary> |
| | | 35 | | /// <param name="errors">The array of validation errors to convert.</param> |
| | | 36 | | /// <returns>A new <see cref="ValidationResponse" /> instance containing the specified errors.</returns> |
| | | 37 | | public static implicit operator ValidationResponse( ColumnValidationError[] errors ) => |
| | 3 | 38 | | new() |
| | 3 | 39 | | { |
| | 3 | 40 | | Errors = errors.ToList() |
| | 3 | 41 | | }; |
| | | 42 | | |
| | | 43 | | /// <summary> |
| | | 44 | | /// Implicitly converts a single validation error to a <see cref="ValidationResponse" />. |
| | | 45 | | /// </summary> |
| | | 46 | | /// <param name="errors">The validation error to convert.</param> |
| | | 47 | | /// <returns>A new <see cref="ValidationResponse" /> instance containing the specified error.</returns> |
| | | 48 | | public static implicit operator ValidationResponse( ColumnValidationError errors ) => |
| | 3 | 49 | | new() |
| | 3 | 50 | | { |
| | 3 | 51 | | Errors = [errors] |
| | 3 | 52 | | }; |
| | | 53 | | } |