예제 #1
0
        internal static Validator GetPropertyValidatorFromConfiguration(Type type, PropertyInfo propertyInfo,
                                                                        string ruleset, MemberAccessValidatorBuilderFactory memberAccessValidatorBuilderFactory)
        {
            Validator validator = null;

            lock (defaultConfigurationOnlyPropertyValidatorsCacheLock)
            {
                PropertyValidatorCacheKey key = new PropertyValidatorCacheKey(type, propertyInfo.Name, ruleset);
                if (!defaultConfigurationOnlyPropertyValidatorsCache.TryGetValue(key, out validator))
                {
                    ConfigurationValidatorBuilder builder = GetConfigurationValidatorBuilder(memberAccessValidatorBuilderFactory);

                    ValidatedPropertyReference propertyReference = GetValidatedPropertyReference(type, ruleset, propertyInfo.Name, builder.ConfigurationSource);
                    if (null == propertyReference)
                    {
                        validator = null;
                    }
                    else
                    {
                        validator = builder.CreateValidatorForProperty(type, propertyReference);
                    }

                    defaultConfigurationOnlyPropertyValidatorsCache[key] = validator;
                }
            }

            return(validator);
        }
예제 #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="type"></param>
        /// <param name="propertyInfo"></param>
        /// <param name="ruleset"></param>
        /// <param name="memberAccessValidatorBuilderFactory"></param>
        /// <returns></returns>
        public static Validator GetPropertyValidatorFromValidationAttributes(
            Type type,
            PropertyInfo propertyInfo,
            string ruleset,
            MemberAccessValidatorBuilderFactory memberAccessValidatorBuilderFactory)
        {
            Validator validator = null;

            lock (validationAttributeOnlyPropertyValidatorsCache)
            {
                var key = new PropertyValidatorCacheKey(type, propertyInfo.Name, ruleset);
                if (!validationAttributeOnlyPropertyValidatorsCache.TryGetValue(key, out validator))
                {
                    validator =
                        string.IsNullOrEmpty(ruleset)
                            ? new ValidationAttributeValidatorBuilder(memberAccessValidatorBuilderFactory, ValidationFactory.DefaultCompositeValidatorFactory)
                        .CreateValidatorForProperty(propertyInfo)
                            : new AndCompositeValidator();

                    validationAttributeOnlyPropertyValidatorsCache[key] = validator;
                }
            }

            return(validator);
        }
예제 #3
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 attributesValidator    = GetPropertyValidatorFromAttributes(type, propertyInfo, ruleset, memberAccessValidatorBuilderFactory);
                    Validator configurationValidator = GetPropertyValidatorFromConfiguration(type, propertyInfo, ruleset, memberAccessValidatorBuilderFactory);

                    if (null != attributesValidator && null != configurationValidator)
                    {
                        validator = new AndCompositeValidator(attributesValidator, configurationValidator);
                    }
                    else if (null != attributesValidator)
                    {
                        validator = attributesValidator;
                    }
                    else
                    {
                        validator = configurationValidator;
                    }

                    attributeAndDefaultConfigurationPropertyValidatorsCache[key] = validator;
                }
            }

            return(validator);
        }
예제 #4
0
        internal static Validator GetPropertyValidatorFromAttributes(Type type, PropertyInfo propertyInfo, string ruleset, MemberAccessValidatorBuilderFactory memberAccessValidatorBuilderFactory)
        {
            Validator validator = null;

            lock (attributeOnlyPropertyValidatorsCacheLock)
            {
                PropertyValidatorCacheKey key = new PropertyValidatorCacheKey(type, propertyInfo.Name, ruleset);
                if (!attributeOnlyPropertyValidatorsCache.TryGetValue(key, out validator))
                {
                    validator = GetTypeValidatorBuilder(memberAccessValidatorBuilderFactory).CreateValidatorForProperty(propertyInfo, ruleset);
                    attributeOnlyPropertyValidatorsCache[key] = validator;
                }
            }
            return(validator);
        }
예제 #5
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);
            }
        }