Beispiel #1
0
        private static ConfigurationValidatorBuilder GetConfigurationValidatorBuilder(MemberAccessValidatorBuilderFactory memberAccessValidatorBuilderFactory)
        {
            IConfigurationSource          configurationSource = ConfigurationSourceFactory.Create();
            ConfigurationValidatorBuilder builder             = new ConfigurationValidatorBuilder(configurationSource, memberAccessValidatorBuilderFactory);

            return(builder);
        }
Beispiel #2
0
        private static Validator InnerCreateValidatorFromConfiguration(Type targetType, string ruleset, IConfigurationSource configurationSource)
        {
            ConfigurationValidatorBuilder builder = new ConfigurationValidatorBuilder(configurationSource);
            Validator validator = builder.CreateValidator(targetType, ruleset);

            return(validator);
        }
Beispiel #3
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);
        }
        /// <summary>
        /// Creates the validator for the specified target and ruleset.
        /// </summary>
        /// <param name="targetType">The <see cref="Type"/>to validate.</param>
        /// <param name="ruleset">The ruleset to use when validating</param>
        /// <param name="mainValidatorFactory">Factory to use when building nested validators.</param>
        /// <returns>A <see cref="Validator"/></returns>
        protected internal override Validator InnerCreateValidator(Type targetType, string ruleset, ValidatorFactory mainValidatorFactory)
        {
            ConfigurationValidatorBuilder builder =
                new ConfigurationValidatorBuilder(
                    ValidationSettings.TryGet(ConfigurationSource),
                    MemberAccessValidatorBuilderFactory.Default,
                    mainValidatorFactory);

            return builder.CreateValidator(targetType, ruleset);
        }
Beispiel #5
0
        /// <summary>
        /// Creates the validator for the specified target and ruleset.
        /// </summary>
        /// <param name="targetType">The <see cref="Type"/>to validate.</param>
        /// <param name="ruleset">The ruleset to use when validating</param>
        /// <param name="mainValidatorFactory">Factory to use when building nested validators.</param>
        /// <returns>A <see cref="Validator"/></returns>
        protected internal override Validator InnerCreateValidator(Type targetType, string ruleset, ValidatorFactory mainValidatorFactory)
        {
            ConfigurationValidatorBuilder builder =
                new ConfigurationValidatorBuilder(
                    ValidationSettings.TryGet(ConfigurationSource),
                    MemberAccessValidatorBuilderFactory.Default,
                    mainValidatorFactory);

            return(builder.CreateValidator(targetType, ruleset));
        }