private void CreateConverter() {
// Some properties cannot have type converters.
// Such examples are properties that are ConfigurationElement ( derived classes )
// or properties which are user-defined and the user code handles serialization/desirialization so
// the property itself is never converted to/from string
if (_converter == null) {
// Enums are exception. We use our custom converter for all enums
if (_type.IsEnum) {
_converter = new GenericEnumConverter(_type);
}
else if (!_type.IsSubclassOf(typeof(ConfigurationElement))) {
_converter = TypeDescriptor.GetConverter(_type);
if ((_converter == null) ||
!_converter.CanConvertFrom(typeof(String)) ||
!_converter.CanConvertTo(typeof(String))) {
throw new ConfigurationErrorsException(SR.GetString(SR.No_converter, _name, _type.Name));
}
}
}
}
}