Пример #1
0
 public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
 {
     if (destinationType == (Type)null)
     {
         throw new ArgumentNullException(nameof(destinationType));
     }
     if (value != null && value is SplitterLength)
     {
         SplitterLength length = (SplitterLength)value;
         if (destinationType == typeof(string))
         {
             return((object)SplitterLengthConverter.ToString(length, culture));
         }
         if (destinationType.IsEquivalentTo(typeof(InstanceDescriptor)))
         {
             return((object)new InstanceDescriptor((MemberInfo)typeof(SplitterLength).GetConstructor(new Type[2]
             {
                 typeof(double),
                 typeof(SplitterUnitType)
             }), (ICollection) new object[2]
             {
                 (object)length.Value,
                 (object)length.SplitterUnitType
             }));
         }
     }
     throw this.GetConvertToException(value, destinationType);
 }
Пример #2
0
        public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
        {
            if (value == null || !this.CanConvertFrom(value.GetType()))
            {
                throw this.GetConvertFromException(value);
            }
            if (value is string)
            {
                return((object)SplitterLengthConverter.FromString((string)value, culture));
            }
            double d = Convert.ToDouble(value, (IFormatProvider)culture);

            if (double.IsNaN(d))
            {
                d = 1.0;
            }
            return((object)new SplitterLength(d, SplitterUnitType.Stretch));
        }
Пример #3
0
 public override string ToString()
 {
     return(SplitterLengthConverter.ToString(this, CultureInfo.InvariantCulture));
 }