Exemplo n.º 1
0
 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));
 }
Exemplo n.º 2
0
 public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
 {
     int[] numArray = MathTypeConverter.ConvertToValues <int>(context, culture, value, 4, new[] { "X", "Y", "Width", "Height" });
     if (numArray != null)
     {
         return(new Rectangle(numArray[0], numArray[1], numArray[2], numArray[3]));
     }
     return(base.ConvertFrom(context, culture, value));
 }
Exemplo n.º 3
0
 public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
 {
     float[] numArray = MathTypeConverter.ConvertToValues <float>(context, culture, value, 2, new[] { "X", "Y" });
     if (numArray != null)
     {
         return(new Vector2(numArray[0], numArray[1]));
     }
     return(base.ConvertFrom(context, culture, value));
 }
Exemplo n.º 4
0
 public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
 {
     byte[] buffer = MathTypeConverter.ConvertToValues <byte>(context, culture, value, 4, new string[] { "R", "G", "B", "A" });
     if (buffer != null)
     {
         return(new Color(buffer[0], buffer[1], buffer[2], buffer[3]));
     }
     return(base.ConvertFrom(context, culture, value));
 }
Exemplo n.º 5
0
 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));
 }
Exemplo n.º 6
0
 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));
 }