public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) {
if (value is string) {
string text = ((string)value).Trim();
try {
if (AllowHex && text[0] == '#') {
return FromString(text.Substring(1), 16);
}
else if (AllowHex && text.StartsWith("0x")
|| text.StartsWith("0X")
|| text.StartsWith("&h")
|| text.StartsWith("&H")) {
return FromString(text.Substring(2), 16);
}
else {
if (culture == null) {
culture = CultureInfo.CurrentCulture;
}
NumberFormatInfo formatInfo = (NumberFormatInfo)culture.GetFormat(typeof(NumberFormatInfo));
return FromString(text, formatInfo);
}
}
catch (Exception e) {
throw FromStringError(text, e);
}
catch { throw; }
}
return base.ConvertFrom(context, culture, value);
}