/// <devdoc> /// <para>Converts the given object to a <see cref='Gu.Units.SpeedUnit'/> /// object.</para> /// </devdoc> public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) { var text = value as string; if (text != null) { SpeedUnit result; if (SpeedUnit.TryParse(text, out result)) { return(result); } var message = $"Could not convert the string '{text}' to an instance of SpeedUnit)"; throw new NotSupportedException(message); } return(base.ConvertFrom(context, culture, value)); }
public bool Equals(SpeedUnit other) { return(this.symbol == other.symbol); }
public static bool TryParse(string text, out SpeedUnit result) { return(UnitParser <SpeedUnit> .TryParse(text, out result)); }
public string ToString(string format, IFormatProvider formatProvider, SpeedUnit unit) { var quantity = unit.FromSiUnit(this.metresPerSecond); return(string.Format("{0}{1}", quantity.ToString(format, formatProvider), unit.Symbol)); }
/// <summary> /// Initializes a new instance of <see cref="T:Gu.Units.Speed"/>. /// </summary> /// <param name="value"></param> /// <param name="unit"><see cref="T:Gu.Units.MetresPerSecond"/>.</param> public Speed(double value, SpeedUnit unit) { this.metresPerSecond = unit.ToSiUnit(value); }
/// <summary> /// Creates a new instance of <see cref="T:Gu.Units.Speed"/>. /// </summary> /// <param name="value"></param> /// <param name="unit"></param> public static Speed From(double value, SpeedUnit unit) { return(new Speed(unit.ToSiUnit(value))); }