Exemple #1
0
        internal static Validator GetPropertyValidator(Type type, PropertyInfo propertyInfo, string ruleset, ValidationSpecificationSource validationSpecificationSource, MemberAccessValidatorBuilderFactory memberAccessValidatorBuilderFactory)
        {
            if (type == null)
            {
                throw new InvalidOperationException(Resources.ExceptionTypeNotFound);
            }
            if (propertyInfo == null)
            {
                throw new InvalidOperationException(Resources.ExceptionPropertyNotFound);
            }
            if (!propertyInfo.CanRead)
            {
                throw new InvalidOperationException(Resources.ExceptionPropertyNotReadable);
            }
            switch (validationSpecificationSource)
            {
            case ValidationSpecificationSource.Both:
                return(PropertyValidationFactory.GetPropertyValidator(type, propertyInfo, ruleset, memberAccessValidatorBuilderFactory));

            case ValidationSpecificationSource.Attributes:
                return(PropertyValidationFactory.GetPropertyValidatorFromAttributes(type, propertyInfo, ruleset, memberAccessValidatorBuilderFactory));

            default:
                return(null);
            }
        }
Exemple #2
0
        internal static Validator GetPropertyValidatorFromAttributes(Type type, PropertyInfo propertyInfo, string ruleset, MemberAccessValidatorBuilderFactory memberAccessValidatorBuilderFactory)
        {
            Validator validator = null;

            lock (PropertyValidationFactory.attributeOnlyPropertyValidatorsCacheLock)
            {
                PropertyValidationFactory.PropertyValidatorCacheKey key = new PropertyValidationFactory.PropertyValidatorCacheKey(type, propertyInfo.Name, ruleset);
                if (!PropertyValidationFactory.attributeOnlyPropertyValidatorsCache.TryGetValue(key, out validator))
                {
                    validator = PropertyValidationFactory.GetTypeValidatorBuilder(memberAccessValidatorBuilderFactory).CreateValidatorForProperty(propertyInfo, ruleset);
                    PropertyValidationFactory.attributeOnlyPropertyValidatorsCache[key] = validator;
                }
            }
            return(validator);
        }
Exemple #3
0
        internal static Validator GetPropertyValidator(Type type, PropertyInfo propertyInfo, string ruleset, MemberAccessValidatorBuilderFactory memberAccessValidatorBuilderFactory)
        {
            Validator validator = null;

            lock (PropertyValidationFactory.attributeAndDefaultConfigurationPropertyValidatorsCacheLock)
            {
                PropertyValidatorCacheKey key = new PropertyValidatorCacheKey(type, propertyInfo.Name, ruleset);
                if (!PropertyValidationFactory.attributeAndDefaultConfigurationPropertyValidatorsCache.TryGetValue(key, out validator))
                {
                    validator = PropertyValidationFactory.GetPropertyValidatorFromAttributes(type, propertyInfo, ruleset, memberAccessValidatorBuilderFactory);
                    PropertyValidationFactory.attributeAndDefaultConfigurationPropertyValidatorsCache[key] = validator;
                    return(validator);
                }
                return(validator);
            }
        }
Exemple #4
0
 internal static Validator GetPropertyValidator(Type type, PropertyInfo propertyInfo, string ruleset, ValidationSpecificationSource validationSpecificationSource, MemberValueAccessBuilder memberValueAccessBuilder)
 {
     return(PropertyValidationFactory.GetPropertyValidator(type, propertyInfo, ruleset, validationSpecificationSource, new MemberAccessValidatorBuilderFactory(memberValueAccessBuilder)));
 }