public override object ConvertTo( ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) { if (destinationType == null) { throw new ArgumentNullException("destinationType"); } if ((destinationType == typeof(string)) && (value is Rectangle)) { var rect = (Rectangle)value; return(MathTypeConverter.ConvertFromValues <int>(context, culture, new[] { rect.X, rect.Y, rect.Width, rect.Height })); } if ((destinationType == typeof(InstanceDescriptor)) && (value is Rectangle)) { Rectangle rectangle = (Rectangle)value; ConstructorInfo constructor = typeof(Rectangle).GetConstructor(new Type[] { typeof(int), typeof(int), typeof(int), typeof(int) }); if (constructor != null) { return(new InstanceDescriptor( constructor, new object[] { rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height })); } } return(base.ConvertTo(context, culture, value, destinationType)); }
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) { if (destinationType == null) { throw new ArgumentNullException("destinationType"); } if ((destinationType == typeof(string)) && (value is Color)) { Color color2 = (Color)value; return(MathTypeConverter.ConvertFromValues <byte>(context, culture, new byte[] { color2.R, color2.G, color2.B, color2.A })); } if ((destinationType == typeof(InstanceDescriptor)) && (value is Color)) { Color color = (Color)value; ConstructorInfo constructor = typeof(Color).GetConstructor(new Type[] { typeof(byte), typeof(byte), typeof(byte), typeof(byte) }); if (constructor != null) { return(new InstanceDescriptor(constructor, new object[] { color.R, color.G, color.B, color.A })); } } return(base.ConvertTo(context, culture, value, destinationType)); }
public override object ConvertTo( ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) { if (destinationType == null) { throw new ArgumentNullException("destinationType"); } if ((destinationType == typeof(string)) && (value is Vector2)) { var vector2 = (Vector2)value; return(MathTypeConverter.ConvertFromValues <float>(context, culture, new[] { vector2.X, vector2.Y })); } if ((destinationType == typeof(InstanceDescriptor)) && (value is Vector2)) { var vector = (Vector2)value; ConstructorInfo constructor = typeof(Vector2).GetConstructor(new[] { typeof(float), typeof(float) }); if (constructor != null) { return(new InstanceDescriptor(constructor, new object[] { vector.X, vector.Y })); } } return(base.ConvertTo(context, culture, value, destinationType)); }