private List<Validator> GenerateValidators(SchemaObjectBase obj)
		{
			List<Validator> result = new List<Validator>();

			foreach (SchemaPropertyValue pv in obj.Properties)
			{
				foreach (Validator v in pv.Validators)
				{
					ValueAccessValidator validator = new ValueAccessValidator(new SchemaPropertyValueAccess(pv), v, pv.Definition.Name);

					result.Add(validator);
				}
			}

			return result;
		}
Esempio n. 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);
            }
        }
		private void FillValidatorsFromProperty(PropertyInfo info, string ruleset, List<Validator> list)
		{
			CompositeValidatorBuilder builder = GetCompositeValidatorBuilder(info, ruleset);

			foreach (ValidatorAttribute attr in info.GetCustomAttributes(typeof(ValidatorAttribute), true))
			{
				if (attr.Ruleset == ruleset && info.CanRead)
				{
					ValueAccessValidator valueValidator = new ValueAccessValidator(
						new PropertyValueAccess(info),
						attr.CreateValidator(info.PropertyType, info.ReflectedType));

					builder.AddValueValidator(valueValidator);
				}
			}

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