Example #1
0
        public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
        {
            object obj = null;

            if (!destinationType.Equals(typeof(string)))
            {
                obj = base.ConvertTo(context, culture, RuntimeHelpers.GetObjectValue(value), destinationType);
            }
            else
            {
                TranslationScale translationScale = (TranslationScale)value;
                string[]         str = { Conversions.ToString(translationScale.InputMinValue), ",", Conversions.ToString(translationScale.InputMaxValue), ",", Conversions.ToString(translationScale.OutputMinValue), ",", Conversions.ToString(translationScale.OutputMaxValue) };
                obj = string.Concat(str);
            }
            return(obj);
        }
Example #2
0
        public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
        {
            object translationScale = null;

            if (!(value is string))
            {
                translationScale = base.ConvertFrom(context, culture, RuntimeHelpers.GetObjectValue(value));
            }
            else
            {
                string   str       = Conversions.ToString(value);
                string[] strArrays = str.Split(new char[] { ',' });
                try
                {
                    translationScale = new TranslationScale(Conversions.ToDouble(strArrays[0]), Conversions.ToDouble(strArrays[1]), Conversions.ToDouble(strArrays[2]), Conversions.ToDouble(strArrays[3]));
                }
                catch
                {
                    throw new InvalidCastException(Conversions.ToString(value));
                }
            }
            return(translationScale);
        }