Beispiel #1
0
        /// <devdoc>
        /// <para>Converts the given object to a <see cref='Gu.Units.ResistanceUnit'/>
        /// object.</para>
        /// </devdoc>
        public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
        {
            var text = value as string;

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

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

            return(base.ConvertFrom(context, culture, value));
        }
Beispiel #2
0
 /// <summary>
 /// Returns a quantity indicating whether this instance is equal to a specified <see cref="Gu.Units.ResistanceUnit"/> object.
 /// </summary>
 /// <param name="other">An instance of <see cref="Gu.Units.ResistanceUnit"/> object to compare with this instance.</param>
 /// <returns>
 /// true if <paramref name="other"/> represents the same ResistanceUnit as this instance; otherwise, false.
 /// </returns>
 public bool Equals(ResistanceUnit other)
 {
     return(this.symbol == other.symbol);
 }
Beispiel #3
0
 /// <summary>
 /// Creates an instance of <see cref="Gu.Units.ResistanceUnit"/> from its string representation
 /// </summary>
 /// <param name="text">The string representation of the <see cref="Gu.Units.ResistanceUnit"/></param>
 /// <param name="result">The parsed <see cref="ResistanceUnit"/></param>
 /// <returns>True if an instance of <see cref="ResistanceUnit"/> could be parsed from <paramref name="text"/></returns>
 public static bool TryParse(string text, out ResistanceUnit result)
 {
     return(UnitParser <ResistanceUnit> .TryParse(text, out result));
 }
Beispiel #4
0
        public string ToString(string format, IFormatProvider formatProvider, ResistanceUnit unit)
        {
            var quantity = unit.FromSiUnit(this.ohm);

            return(string.Format("{0}{1}", quantity.ToString(format, formatProvider), unit.Symbol));
        }
Beispiel #5
0
 /// <summary>
 /// Initializes a new instance of <see cref="T:Gu.Units.Resistance"/>.
 /// </summary>
 /// <param name="value"></param>
 /// <param name="unit"><see cref="T:Gu.Units.Ohm"/>.</param>
 public Resistance(double value, ResistanceUnit unit)
 {
     this.ohm = unit.ToSiUnit(value);
 }
Beispiel #6
0
 /// <summary>
 /// Creates a new instance of <see cref="T:Gu.Units.Resistance"/>.
 /// </summary>
 /// <param name="value"></param>
 /// <param name="unit"></param>
 public static Resistance From(double value, ResistanceUnit unit)
 {
     return(new Resistance(unit.ToSiUnit(value)));
 }