Ejemplo n.º 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);
 }
Ejemplo n.º 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));
        }
Ejemplo n.º 3
0
 public override string ToString()
 {
     return(SplitterLengthConverter.ToString(this, CultureInfo.InvariantCulture));
 }