Пример #1
0
        public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
        {
            var text = value as string;

            if (text != null)
            {
                TorqueUnit result;
                if (TorqueUnit.TryParse(text, out result))
                {
                    return(result);
                }

                var message = $"Could not convert the string '{text}' to an instance of TorqueUnit)";
                throw new NotSupportedException(message);
            }

            return(base.ConvertFrom(context, culture, value));
        }
Пример #2
0
 /// <summary>
 /// Creates a new instance of <see cref="T:Gu.Units.Torque"/>.
 /// </summary>
 /// <param name="value"></param>
 /// <param name="unit"></param>
 public static Torque From(double value, TorqueUnit unit)
 {
     return(new Torque(unit.ToSiUnit(value)));
 }
Пример #3
0
        public string ToString(string format, IFormatProvider formatProvider, TorqueUnit unit)
        {
            var quantity = unit.FromSiUnit(this.newtonMetres);

            return(string.Format("{0}{1}", quantity.ToString(format, formatProvider), unit.Symbol));
        }
Пример #4
0
 /// <summary>
 /// Initializes a new instance of <see cref="T:Gu.Units.Torque"/>.
 /// </summary>
 /// <param name="value"></param>
 /// <param name="unit"><see cref="T:Gu.Units.NewtonMetres"/>.</param>
 public Torque(double value, TorqueUnit unit)
 {
     this.newtonMetres = unit.ToSiUnit(value);
 }
Пример #5
0
 public bool Equals(TorqueUnit other)
 {
     return(this.symbol == other.symbol);
 }
Пример #6
0
 public static bool TryParse(string text, out TorqueUnit result)
 {
     return(UnitParser <TorqueUnit> .TryParse(text, out result));
 }