Пример #1
0
        public override object ConvertTo(ITypeDescriptorContext typeDescriptorContext, CultureInfo cultureInfo, object value, Type destinationType)
        {
            if (destinationType == null)
            {
                throw new ArgumentNullException(nameof(destinationType));
            }

            if (value is PopupLength == false)
            {
                throw GetConvertToExceptionInt(value, destinationType);
            }

            var flexLength = (PopupLength)value;

            if (destinationType == typeof(string))
            {
                return(PopupLengthConverter.ToString(flexLength, cultureInfo));
            }

            if (destinationType == typeof(InstanceDescriptor))
            {
                return(new InstanceDescriptor(typeof(PopupLength).GetConstructor(new[] { typeof(double), typeof(PopupLengthUnitType) }), new object[] { flexLength.Value, flexLength.UnitType }));
            }

            throw GetConvertToExceptionInt(value, destinationType);
        }
Пример #2
0
        public override object ConvertFrom(ITypeDescriptorContext typeDescriptorContext, CultureInfo cultureInfo, object source)
        {
            if (source == null)
            {
                throw GetConvertFromExceptionInt(null);
            }

            if (source is string stringValue)
            {
                return(PopupLengthConverter.FromString(stringValue, cultureInfo));
            }

            var num = Convert.ToDouble(source, cultureInfo);

            PopupLengthUnitType type;

            if (DoubleUtils.IsNaN(num))
            {
                num  = 1.0;
                type = PopupLengthUnitType.Auto;
            }
            else
            {
                type = PopupLengthUnitType.Absolute;
            }

            return(new PopupLength(num, type));
        }