コード例 #1
0
        public override object ConvertFrom(ITypeDescriptorContext typeDescriptorContext, CultureInfo cultureInfo, object source)
        {
            if (source == null)
            {
                throw GetConvertFromExceptionInt(null);
            }

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

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

            FlexLengthUnitType type;

            if (DoubleUtils.IsNaN(num))
            {
                num  = 1.0;
                type = FlexLengthUnitType.Auto;
            }
            else
            {
                type = FlexLengthUnitType.Pixel;
            }

            return(new FlexLength(num, type));
        }
コード例 #2
0
        public override object ConvertTo(ITypeDescriptorContext typeDescriptorContext, CultureInfo cultureInfo, object value, Type destinationType)
        {
            if (destinationType == null)
            {
                throw new ArgumentNullException(nameof(destinationType));
            }

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

            var flexLength = (FlexLength)value;

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

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

            throw GetConvertToExceptionInt(value, destinationType);
        }
コード例 #3
0
ファイル: FlexLength.cs プロジェクト: Egaros/lib
 public override string ToString()
 {
     return(FlexLengthConverter.ToString(this, CultureInfo.InvariantCulture));
 }