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);
}