예제 #1
0
 public static Validator CreateValidator(ParameterInfo paramInfo)
 {
     MetadataValidatedParameterElement validatedElement = new MetadataValidatedParameterElement();
     validatedElement.UpdateFlyweight(paramInfo);
     CompositeValidatorBuilder builder = new CompositeValidatorBuilder(validatedElement);
     foreach (IValidatorDescriptor descriptor in validatedElement.GetValidatorDescriptors())
     {
         builder.AddValueValidator(descriptor.CreateValidator(paramInfo.ParameterType, null, null));
     }
     return builder.GetValidator();
 }
        public static Validator CreateValidator(ParameterInfo paramInfo)
        {
            MetadataValidatedParameterElement metadataValidatedParameterElement = new MetadataValidatedParameterElement();

            metadataValidatedParameterElement.UpdateFlyweight(paramInfo);
            CompositeValidatorBuilder compositeValidatorBuilder = new CompositeValidatorBuilder(metadataValidatedParameterElement);

            foreach (IValidatorDescriptor validatorDescriptor in metadataValidatedParameterElement.GetValidatorDescriptors())
            {
                compositeValidatorBuilder.AddValueValidator(validatorDescriptor.CreateValidator(paramInfo.ParameterType, null, null));
            }
            return(compositeValidatorBuilder.GetValidator());
        }
예제 #3
0
        protected Validator CreateValidatorForValidatedElement(IValidatedElement validatedElement, CompositeValidatorBuilderCreator validatorBuilderCreator)
        {
            IEnumerator <IValidatorDescriptor> enumerator = validatedElement.GetValidatorDescriptors().GetEnumerator();

            if (!enumerator.MoveNext())
            {
                return(null);
            }
            CompositeValidatorBuilder builder = validatorBuilderCreator(validatedElement);

            do
            {
                Validator valueValidator = enumerator.Current.CreateValidator(validatedElement.TargetType, validatedElement.MemberInfo.ReflectedType, this.memberAccessValidatorFactory.MemberValueAccessBuilder);
                builder.AddValueValidator(valueValidator);
            }while (enumerator.MoveNext());
            return(builder.GetValidator());
        }