public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
        {
            var text = value as string;

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

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

            return(base.ConvertFrom(context, culture, value));
        }
Exemple #2
0
 public bool Equals(AngleUnit other)
 {
     return(this.symbol == other.symbol);
 }
Exemple #3
0
 public static bool TryParse(string text, out AngleUnit result)
 {
     return(UnitParser <AngleUnit> .TryParse(text, out result));
 }
Exemple #4
0
 /// <summary>
 /// Creates a new instance of <see cref="T:Gu.Units.Angle"/>.
 /// </summary>
 /// <param name="value"></param>
 /// <param name="unit"></param>
 public static Angle From(double value, AngleUnit unit)
 {
     return(new Angle(unit.ToSiUnit(value)));
 }
Exemple #5
0
        public string ToString(string format, IFormatProvider formatProvider, AngleUnit unit)
        {
            var quantity = unit.FromSiUnit(this.radians);

            return(string.Format("{0}{1}", quantity.ToString(format, formatProvider), unit.Symbol));
        }
Exemple #6
0
 /// <summary>
 /// Initializes a new instance of <see cref="T:Gu.Units.Angle"/>.
 /// </summary>
 /// <param name="value"></param>
 /// <param name="unit"><see cref="T:Gu.Units.Radians"/>.</param>
 public Angle(double value, AngleUnit unit)
 {
     this.radians = unit.ToSiUnit(value);
 }