public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
{
string strValue = value as string;
if (strValue != null)
{
string text = strValue.Trim();
if (text.Length == 0)
{
return null;
}
else
{
// Parse 2 integer values.
//
if (culture == null)
{
culture = CultureInfo.CurrentCulture;
}
char sep = culture.TextInfo.ListSeparator[0];
string[] tokens = text.Split(sep);
int[] values = new int[tokens.Length];
TypeConverter intConverter = TypeDescriptor.GetConverter(typeof(int));
for (int i = 0; i < values.Length; i++)
{
// Note: ConvertFromString will raise exception if value cannot be converted.
values[i] = (int)intConverter.ConvertFromString(context, culture, tokens[i]);
}
if (values.Length == 2)
{
return new Point(values[0], values[1]);
}
else
{
throw new ArgumentException(SR.Format(SR.TextParseFailedFormat,
text,
"x, y"));
}
}
}
return base.ConvertFrom(context, culture, value);
}