public static bool TryCollectResults(this ICanBeValidated rootValue, ICollection <ValidationResult> results, IServiceProvider serviceProvider, IDictionary <object, object> items = null) { var context = new ValidationContext(rootValue, items); if (serviceProvider != null) { context.InitializeServiceProvider(serviceProvider.GetService); } return(ValidationUtilities.TryCollectResults(context, rootValue, results)); }
public static void CollectErrors(this ICanBeValidated value, ICollection <string> errors, IServiceProvider serviceProvider = null) { var results = new List <ValidationResult>(); if (!value.TryCollectResults(results, serviceProvider)) { foreach (var result in results.Where(r => r != ValidationResult.Success)) { errors.Add(result.ErrorMessage); } } }