| | | 1 | | namespace ZhEaIsNsAaBn.Utilities.ValidationResponses; |
| | | 2 | | |
| | | 3 | | /// <summary> |
| | | 4 | | /// Represents a bulk validation response that contains multiple validation results. |
| | | 5 | | /// Provides convenient implicit conversion operators for creating instances from various input types. |
| | | 6 | | /// </summary> |
| | | 7 | | /// <typeparam name="T">The type of data being validated.</typeparam> |
| | | 8 | | public class BulkValidationResponse< T > |
| | | 9 | | { |
| | | 10 | | /// <summary> |
| | | 11 | | /// Gets or sets the list of validation responses for individual rows or items. |
| | | 12 | | /// </summary> |
| | | 13 | | /// <value>A list of <see cref="ValidationResponse{T}" /> objects representing validation results for each item.</va |
| | 6 | 14 | | public List<ValidationResponse<T>> Rows { get; set; } = new(); |
| | | 15 | | |
| | | 16 | | /// <summary> |
| | | 17 | | /// Gets a value indicating whether all validation responses in the collection are valid. |
| | | 18 | | /// </summary> |
| | | 19 | | /// <value><c>true</c> if all items in <see cref="Rows" /> are valid; otherwise, <c>false</c>.</value> |
| | 6 | 20 | | public bool IsValid => Rows.TrueForAll( x => x.IsValid ); |
| | | 21 | | |
| | | 22 | | /// <summary> |
| | | 23 | | /// Implicitly converts a single value to a <see cref="BulkValidationResponse{T}" /> containing that value. |
| | | 24 | | /// </summary> |
| | | 25 | | /// <param name="value">The value to convert.</param> |
| | | 26 | | /// <returns>A new <see cref="BulkValidationResponse{T}" /> instance containing the specified value.</returns> |
| | | 27 | | public static implicit operator BulkValidationResponse<T>( T value ) => |
| | 0 | 28 | | new() |
| | 0 | 29 | | { |
| | 0 | 30 | | Rows = [value] |
| | 0 | 31 | | }; |
| | | 32 | | |
| | | 33 | | /// <summary> |
| | | 34 | | /// Implicitly converts a single <see cref="ValidationResponse{T}" /> to a <see cref="BulkValidationResponse{T}" |
| | | 35 | | /// </summary> |
| | | 36 | | /// <param name="validation">The validation response to convert.</param> |
| | | 37 | | /// <returns>A new <see cref="BulkValidationResponse{T}" /> instance containing the specified validation response.</ |
| | | 38 | | public static implicit operator BulkValidationResponse<T>( ValidationResponse<T> validation ) => |
| | 0 | 39 | | new() |
| | 0 | 40 | | { |
| | 0 | 41 | | Rows = [validation] |
| | 0 | 42 | | }; |
| | | 43 | | |
| | | 44 | | /// <summary> |
| | | 45 | | /// Implicitly converts a list of <see cref="ValidationResponse{T}" /> objects to a |
| | | 46 | | /// <see cref="BulkValidationResponse{T}" />. |
| | | 47 | | /// </summary> |
| | | 48 | | /// <param name="validation">The list of validation responses to convert.</param> |
| | | 49 | | /// <returns>A new <see cref="BulkValidationResponse{T}" /> instance containing the specified validation responses.< |
| | | 50 | | public static implicit operator BulkValidationResponse<T>( List<ValidationResponse<T>> validation ) => |
| | 6 | 51 | | new() |
| | 6 | 52 | | { |
| | 6 | 53 | | Rows = validation |
| | 6 | 54 | | }; |
| | | 55 | | } |