using System.Collections.Generic; using System.Linq; namespace Swan.Validators { /// /// Defines a validation result containing all validation errors and their properties. /// public class ObjectValidationResult { private readonly List _errors = new List(); /// /// A list of errors. /// public IReadOnlyList Errors => _errors; /// /// true if there are no errors; otherwise, false. /// public bool IsValid => !Errors.Any(); /// /// Adds an error with a specified property name. /// /// The property name. /// The error message. public void Add(string propertyName, string errorMessage) => _errors.Add(new ValidationError(errorMessage, propertyName)); /// /// Defines a validation error. /// public class ValidationError { /// /// Initializes a new instance of the class. /// /// Name of the property. /// The error message. public ValidationError(string propertyName, string errorMessage) { PropertyName = propertyName; ErrorMessage = errorMessage; } /// /// The property name. /// public string PropertyName { get; } /// /// The message error. /// public string ErrorMessage { get; } } } }