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)
            {
                PropertyValidatorCacheKey key = new 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);
                }
                return(validator);
            }
        }
Exemple #3
0
 private static MetadataValidatorBuilder GetTypeValidatorBuilder(MemberAccessValidatorBuilderFactory memberAccessValidatorBuilderFactory)
 {
     return(new MetadataValidatorBuilder(memberAccessValidatorBuilderFactory));
 }
 public MetadataValidatorBuilder(MemberAccessValidatorBuilderFactory memberAccessValidatorFactory) : base(memberAccessValidatorFactory)
 {
 }
Exemple #5
0
        internal static Validator GetPropertyValidator(Type type, PropertyInfo propertyInfo, string ruleset, MemberAccessValidatorBuilderFactory memberAccessValidatorBuilderFactory)
        {
            Validator validator = null;

            lock (attributeAndDefaultConfigurationPropertyValidatorsCacheLock)
            {
                PropertyValidatorCacheKey key = new PropertyValidatorCacheKey(type, propertyInfo.Name, ruleset);
                if (!attributeAndDefaultConfigurationPropertyValidatorsCache.TryGetValue(key, out validator))
                {
                    validator = GetPropertyValidatorFromAttributes(type, propertyInfo, ruleset, memberAccessValidatorBuilderFactory);
                    attributeAndDefaultConfigurationPropertyValidatorsCache[key] = validator;
                }
            }
            return(validator);
        }
 public ValidatorBuilderBase(MemberAccessValidatorBuilderFactory memberAccessValidatorFactory)
 {
     this.memberAccessValidatorFactory = memberAccessValidatorFactory;
 }
 public MetadataValidatorBuilder(MemberAccessValidatorBuilderFactory memberAccessValidatorFactory)
     : base(memberAccessValidatorFactory)
 {
 }
 public ValidatorBuilderBase(MemberAccessValidatorBuilderFactory memberAccessValidatorFactory)
 {
     this.memberAccessValidatorFactory = memberAccessValidatorFactory;
 }