Exemplo n.º 1
0
        /// <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));
        }
Exemplo n.º 2
0
 public bool Equals(SpeedUnit other)
 {
     return(this.symbol == other.symbol);
 }
Exemplo n.º 3
0
 public static bool TryParse(string text, out SpeedUnit result)
 {
     return(UnitParser <SpeedUnit> .TryParse(text, out result));
 }
Exemplo n.º 4
0
        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));
        }
Exemplo n.º 5
0
 /// <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);
 }
Exemplo n.º 6
0
 /// <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)));
 }