public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) { if (destinationType == typeof(string)) { if (value == null) { return("null"); } else { char ch = ';'; if (culture == null) { ch = CultureInfo.CurrentCulture.TextInfo.ListSeparator[0]; } else { ch = culture.TextInfo.ListSeparator[0]; } RectangleD rectangle = (RectangleD)value; return(RectangleDHelper.ConvertRectangleDToString(rectangle, ch)); } } if (destinationType == typeof(InstanceDescriptor) && value != null) { RectangleD rectangle = (RectangleD)value; Type[] types = new Type[] { typeof(double), typeof(double), typeof(double), typeof(double) }; ConstructorInfo info = typeof(RectangleD).GetConstructor(types); if (info != null) { object[] objs = new object[] { rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height }; return(CreateNewInstanceDescriptor(info, objs)); } } return(base.ConvertTo(context, culture, value, destinationType)); }
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) { if (value is string) { char ch; if (culture == null) { ch = CultureInfo.CurrentCulture.TextInfo.ListSeparator[0]; } else { ch = culture.TextInfo.ListSeparator[0]; } string str = value as string; return(RectangleDHelper.ConvertStringToRectangleD(str, ch)); } return(base.ConvertFrom(context, culture, value)); }