public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
{
if (destinationType == null)
{
throw new ArgumentNullException(nameof(destinationType));
}
if (value is Point)
{
if (destinationType == typeof(string))
{
Point pt = (Point)value;
if (culture == null)
{
culture = CultureInfo.CurrentCulture;
}
string sep = culture.TextInfo.ListSeparator + " ";
TypeConverter intConverter = TypeDescriptor.GetConverter(typeof(int));
string[] args = new string[2];
int nArg = 0;
// Note: ConvertToString will raise exception if value cannot be converted.
args[nArg++] = intConverter.ConvertToString(context, culture, pt.X);
args[nArg++] = intConverter.ConvertToString(context, culture, pt.Y);
return string.Join(sep, args);
}
if (destinationType == typeof(InstanceDescriptor))
{
Point pt = (Point)value;
ConstructorInfo ctor = typeof(Point).GetConstructor(new Type[] { typeof(int), typeof(int) });
if (ctor != null)
{
return new InstanceDescriptor(ctor, new object[] { pt.X, pt.Y });
}
}
}
return base.ConvertTo(context, culture, value, destinationType);
}