Пример #1
0
        private void GetValidatorsFromType(Type type, string ruleset, List <Validator> list)
        {
            CompositeValidatorBuilder builder = GetCompositeValidatorBuilder(type, ruleset);

            foreach (ValidatorAttribute attr in type.GetCustomAttributes(typeof(ValidatorAttribute), true))
            {
                if (attr.Ruleset == ruleset)
                {
                    builder.AddValueValidator(attr.CreateValidator(type, type.ReflectedType));
                }
            }

            if (builder.GetCompositeValidatorsCount() != 0)
            {
                Validator result = builder.GetValidator();
                result.Source = type.FullName;
                list.Add(result);
            }
        }
Пример #2
0
        private void FillValidatorsFromField(FieldInfo info, string ruleset, List <Validator> list)
        {
            CompositeValidatorBuilder builder = GetCompositeValidatorBuilder(info, ruleset);

            foreach (ValidatorAttribute attr in info.GetCustomAttributes(typeof(ValidatorAttribute), true))
            {
                if (attr.Ruleset == ruleset)
                {
                    ValueAccessValidator valueValidator = new ValueAccessValidator(
                        new FieldValueAccess(info),
                        attr.CreateValidator(info.FieldType, info.ReflectedType));

                    builder.AddValueValidator(valueValidator);
                }
            }

            if (builder.GetCompositeValidatorsCount() != 0)
            {
                Validator result = builder.GetValidator();
                result.Source = info.Name;
                list.Add(result);
            }
        }