using System.Collections.Generic; using System.ComponentModel.DataAnnotations; namespace AsbCloudInfrastructure; public static class ValidationExtensions { public static bool Validate(this IValidatableObject validatableObject, ICollection validationResults) { var validationContext = new ValidationContext(validatableObject, serviceProvider: null, items: null); foreach (var validationResult in validatableObject.Validate(validationContext)) validationResults.Add(validationResult); return Validator.TryValidateObject(validatableObject, validationContext, validationResults, true); } }