public override void Validate(object instance) { // Images are not required so they could be null // and there is nothing to validate in this case if (instance == null) { return; } var imagesCollection = instance as ICollection <ImageMappingDto>; foreach (var image in imagesCollection) { var imageValidationAttribute = new ImageValidationAttribute(); imageValidationAttribute.Validate(image); var errorsForImage = imageValidationAttribute.GetErrors(); if (errorsForImage.Count > 0) { _errors = errorsForImage; break; } } }
public override async Task ValidateAsync(object instance) { // Images are not required so they could be null // and there is nothing to validate in this case if (instance is ICollection <ImageMappingDto> imagesCollection) { foreach (var image in imagesCollection) { var imageValidationAttribute = new ImageValidationAttribute(); await imageValidationAttribute.ValidateAsync(image); var errorsForImage = imageValidationAttribute.GetErrors(); if (errorsForImage.Count > 0) { _errors = errorsForImage; break; } } } }