Пример #1
0
        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));
        }
Пример #2
0
        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);
                }
            }
        }