TypeConverters and null
===

I am using a class to store connection strings. My app reads a setting from the settings class and assigns it to an instance variable. This is then bound to some controls. My connection string class has the following attribute set:

    [TypeConverter(typeof(ConnectionStringConverter))]

My type convertor looks like is below.

The problem is that if the settings in the settings file is blank the settings class returns null. and not an instance of my connection string class using the default constructor.

Please could someone help me in solving this riddle.

Thanks.


	public class ConnectionStringConverter : TypeConverter
	{
		public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
		{
			if (sourceType == typeof(string))
				return true;
			else
				return base.CanConvertFrom(context, sourceType);
		}

		public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
		{
			if (value is string)
				return (ConnectionString)(value as string);
			else
				return base.ConvertFrom(context, culture, value);
		}

		public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
		{
			if (destinationType == typeof(string))
				return (string)(value as ConnectionString);
			else
				return base.ConvertTo(context, culture, value, destinationType);
		}
	}
