CanValidate() публичный Метод

public CanValidate ( Type type ) : bool
type System.Type
Результат bool
Пример #1
0
        private void ConstructorInit(
            string name,
            Type type,
            ConfigurationPropertyOptions options,
            ConfigurationValidatorBase validator,
            TypeConverter converter,
            string description)
        {
            if (typeof(ConfigurationSection).IsAssignableFrom(type))
            {
                throw new ConfigurationErrorsException(
                          SR.Format(SR.Config_properties_may_not_be_derived_from_configuration_section, name));
            }

            // save the provided name so we can check for default collection names
            ProvidedName = name;

            if (((options & ConfigurationPropertyOptions.IsDefaultCollection) != 0) && string.IsNullOrEmpty(name))
            {
                name = DefaultCollectionPropertyName;
            }
            else
            {
                ValidatePropertyName(name);
            }

            Name        = name;
            Description = description;
            Type        = type;
            _options    = options;
            Validator   = validator;
            _converter  = converter;

            // Use the default validator if none was supplied
            if (Validator == null)
            {
                Validator = s_defaultValidatorInstance;
            }
            else
            {
                // Make sure the supplied validator supports the type of this property
                if (!Validator.CanValidate(Type))
                {
                    throw new ConfigurationErrorsException(SR.Format(SR.Validator_does_not_support_prop_type, Name));
                }
            }
        }
 private static void CachePerTypeValidator(Type type, ConfigurationValidatorBase validator)
 {
     if (s_perTypeValidators == null)
     {
         s_perTypeValidators = new Dictionary<Type, ConfigurationValidatorBase>();
     }
     if (!validator.CanValidate(type))
     {
         throw new ConfigurationErrorsException(System.Configuration.SR.GetString("Validator_does_not_support_elem_type", new object[] { type.Name }));
     }
     s_perTypeValidators.Add(type, validator);
 }
        private static void CachePerTypeValidator( Type type, ConfigurationValidatorBase validator ) {
            Debug.Assert((type != null) && ( validator != null));
            Debug.Assert(typeof(ConfigurationElement).IsAssignableFrom(type));

            // Use the same lock as the property bag lock since in the current implementation
            // the only way to get to this method is through the code path that locks the property bag cache first ( see PropertiesFromType() )

            // NOTE[ Thread Safety ]: Non-guarded access to static variable - since this code is called only from CreatePropertyBagFromType
            // which in turn is done onle once per type and is guarded by the s_propertyBag.SyncRoot then this call is thread safe as well
            if (s_perTypeValidators == null ) {
                    s_perTypeValidators = new Dictionary<Type,ConfigurationValidatorBase>();
            }

            // A type validator should be cached only once. If it isn't then attribute parsing is done more then once which should be avoided
            Debug.Assert( !s_perTypeValidators.ContainsKey(type));

            // Make sure the supplied validator supports validating this object
            if (!validator.CanValidate(type)) {
                throw new ConfigurationErrorsException(SR.GetString(SR.Validator_does_not_support_elem_type, 
                                                       type.Name));
            }

            s_perTypeValidators.Add(type, validator);
        }