Exemple #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);
            }
        }
Exemple #2
0
        private CompositeValidatorBuilder GetCompositeValidatorBuilder(MemberInfo info, string ruleset)
        {
            CompositeValidatorBuilder builder = null;

            foreach (ValidatorCompositionAttribute attr in info.GetCustomAttributes(typeof(ValidatorCompositionAttribute), true))
            {
                if (attr.Ruleset == ruleset)
                {
                    builder = new CompositeValidatorBuilder(attr.CompositionType, attr.MessageTemplate);
                    break;
                }
            }

            if (builder == null)
            {
                builder = new CompositeValidatorBuilder(CompositionType.And);
            }

            return(builder);
        }
Exemple #3
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);
            }
        }
		private CompositeValidatorBuilder GetCompositeValidatorBuilder(MemberInfo info, string ruleset)
		{
			CompositeValidatorBuilder builder = null;

			foreach (ValidatorCompositionAttribute attr in info.GetCustomAttributes(typeof(ValidatorCompositionAttribute), true))
			{
				if (attr.Ruleset == ruleset)
				{
					builder = new CompositeValidatorBuilder(attr.CompositionType, attr.MessageTemplate);
					break;
				}
			}

			if (builder == null)
				builder = new CompositeValidatorBuilder(CompositionType.And);

			return builder;
		}