Beispiel #1
0
        public static Validator CreateValidator(ParameterInfo paramInfo)
        {
            var parameterElement = new MetadataValidatedParameterElement();

            parameterElement.UpdateFlyweight(paramInfo);
            var compositeBuilder = new CompositeValidatorBuilder(parameterElement);

            foreach (IValidatorDescriptor descriptor in parameterElement.GetValidatorDescriptors())
            {
                compositeBuilder.AddValueValidator(descriptor.CreateValidator(paramInfo.ParameterType,
                                                                              null, null,
                                                                              ValidationFactory.DefaultCompositeValidatorFactory));
            }
            return(compositeBuilder.GetValidator());
        }
        protected Validator CreateValidatorForValidatedElement(IValidatedElement validatedElement,
                                                               CompositeValidatorBuilderCreator validatorBuilderCreator)
        {
            IEnumerator <IValidatorDescriptor> validatorDescriptorsEnumerator =
                validatedElement.GetValidatorDescriptors().GetEnumerator();

            if (!validatorDescriptorsEnumerator.MoveNext())
            {
                return(null);
            }

            CompositeValidatorBuilder validatorBuilder = validatorBuilderCreator(validatedElement);

            do
            {
                Validator validator = validatorDescriptorsEnumerator.Current.CreateValidator(validatedElement.TargetType,
                                                                                             validatedElement.MemberInfo.ReflectedType,
                                                                                             _memberAccessValidatorFactory.MemberValueAccessBuilder,
                                                                                             _validatorFactory);
                validatorBuilder.AddValueValidator(validator);
            }while (validatorDescriptorsEnumerator.MoveNext());

            return(validatorBuilder.GetValidator());
        }