public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
        {
            if (VectorConversion.CanConvertTo(context, destinationType))
                return true;
            if (destinationType == typeof(string))
                return true;

            return base.CanConvertTo(context, destinationType);
        }
示例#2
0
        public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
        {
            Vector2 vec = (Vector2)value;

            if (VectorConversion.CanConvertTo(context, destinationType))
            {
                Vector4 vec4 = new Vector4(vec.X, vec.Y, 0.0f, 0.0f);
                return(VectorConversion.ConvertToFromVector4(context, culture, vec4, destinationType));
            }

            if (destinationType == typeof(string))
            {
                string[] terms = new string[2];
                terms[0] = vec.X.ToString(culture);
                terms[1] = vec.Y.ToString(culture);

                return(string.Join(culture.NumberFormat.NumberGroupSeparator, terms));
            }

            return(base.ConvertTo(context, culture, value, destinationType));
        }
示例#3
0
        public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
        {
            var vec = (Vector2)value;

            if (VectorConversion.CanConvertTo(context, destinationType))
            {
                var vec4 = new Vector4(vec.X, vec.Y, 0.0f, 0.0f);
                return(VectorConversion.ConvertToFromVector4(context, culture, vec4, destinationType));
            }

            if (destinationType == typeof(string))
            {
                var terms = new string[2];
                terms[0] = vec.X.ToString("R", culture);
                terms[1] = vec.Y.ToString("R", culture);

                return(string.Join(culture.TextInfo.ListSeparator + " ", terms));
            }

            return(base.ConvertTo(context, culture, value, destinationType));
        }