public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) { if (destinationType == (Type)null) { throw new ArgumentNullException("destinationType"); } if (value != null && value is SplitterLength) { SplitterLength length = (SplitterLength)value; if (destinationType == typeof(string)) { return((object)SplitterLengthConverter.ToString(length, culture)); } if (destinationType == 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); }
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) { if (value == null || !this.CanConvertFrom(value.GetType())) { throw this.GetConvertFromException(value); } string s = value as string; if (s != null) { return((object)SplitterLengthConverter.FromString(s, culture)); } double d = Convert.ToDouble(value, (IFormatProvider)culture); if (double.IsNaN(d)) { d = 1.0; } return((object)new SplitterLength(d, SplitterUnitType.Stretch)); }
public override string ToString() { return(SplitterLengthConverter.ToString(this, CultureInfo.InvariantCulture)); }