Beispiel #1
0
        public static void AddRule(Type type, PropertyInfo pi, ValidateAttribute attr)
        {
            var typeRules = TypePropertyRulesMap.TryGetValue(type, out var rules)
                ? rules
                : TypePropertyRulesMap[type] = new List <IValidationRule>();

            var rule = typeRules.FirstOrDefault(x => (x as PropertyRule)?.PropertyName == pi.Name);

            if (rule == null)
            {
                typeRules.Add(rule = CreatePropertyRule(type, pi));
            }

            var validators = (List <IPropertyValidator>)rule.Validators;

            validators.AddRule(pi, attr);
        }
Beispiel #2
0
 public static List <IValidationRule> GetPropertyRules(Type type) => TypePropertyRulesMap.TryGetValue(type, out var rules)
     ? rules
     : TypeConstants <IValidationRule> .EmptyList;