public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
{
var str = value as string;
if (str != null)
{
string text = str.Trim();
try
{
object result;
if (AllowHex && text[0] == '#')
{
result = FromString(text.Substring(1), 16);
return result;
}
if ((AllowHex && text.StartsWith("0x", StringComparison.OrdinalIgnoreCase)) || text.StartsWith("&h", StringComparison.OrdinalIgnoreCase))
{
result = FromString(text.Substring(2), 16);
return result;
}
culture = culture ?? CultureInfo.CurrentCulture;
var formatInfo = (NumberFormatInfo)culture.GetFormat(typeof(NumberFormatInfo));
result = FromString(text, formatInfo);
return result;
}
catch (Exception innerException)
{
throw new Exception(text, innerException);
}
}
return base.ConvertFrom(context, culture, value);
}