Example #1
0
        /// <summary>
        /// 验证一个规则
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="validator"></param>
        /// <returns></returns>
        public static ValidationResult Validate <T>(this IValidator <T> validator)
        {
            var data = validator.Validate();

            if (data.IsNullOrEmpty())
            {
                return(new ValidationResult());
            }

            var list = new List <ValidationFailure>();

            foreach (var r in data)
            {
                Validator <object> .AddErrors(list, r.Key.Body, r.Value);
            }

            return(new ValidationResult(list));
        }