Exemplo n.º 1
0
        /// <inheritdoc />
        public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
        {
            var text = value as string;

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

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

            return(base.ConvertFrom(context, culture, value));
        }
Exemplo n.º 2
0
        public string ToString(string format, IFormatProvider formatProvider, VolumeUnit unit)
        {
            var quantity = unit.FromSiUnit(this.cubicMetres);

            return(string.Format("{0}{1}", quantity.ToString(format, formatProvider), unit.Symbol));
        }
Exemplo n.º 3
0
 /// <summary>
 /// Initializes a new instance of <see cref="T:Gu.Units.Volume"/>.
 /// </summary>
 /// <param name="value"></param>
 /// <param name="unit"><see cref="T:Gu.Units.CubicMetres"/>.</param>
 public Volume(double value, VolumeUnit unit)
 {
     this.cubicMetres = unit.ToSiUnit(value);
 }
Exemplo n.º 4
0
 /// <summary>
 /// Creates a new instance of <see cref="T:Gu.Units.Volume"/>.
 /// </summary>
 /// <param name="value"></param>
 /// <param name="unit"></param>
 public static Volume From(double value, VolumeUnit unit)
 {
     return(new Volume(unit.ToSiUnit(value)));
 }
Exemplo n.º 5
0
 /// <summary>
 /// Returns a quantity indicating whether this instance is equal to a specified <see cref="Gu.Units.VolumeUnit"/> object.
 /// </summary>
 /// <param name="other">An instance of <see cref="Gu.Units.VolumeUnit"/> object to compare with this instance.</param>
 /// <returns>
 /// true if <paramref name="other"/> represents the same VolumeUnit as this instance; otherwise, false.
 /// </returns>
 public bool Equals(VolumeUnit other)
 {
     return(this.symbol == other.symbol);
 }
Exemplo n.º 6
0
 /// <summary>
 /// Creates an instance of <see cref="Gu.Units.VolumeUnit"/> from its string representation
 /// </summary>
 /// <param name="text">The string representation of the <see cref="Gu.Units.VolumeUnit"/></param>
 /// <param name="result">The parsed <see cref="VolumeUnit"/></param>
 /// <returns>True if an instance of <see cref="VolumeUnit"/> could be parsed from <paramref name="text"/></returns>
 public static bool TryParse(string text, out VolumeUnit result)
 {
     return(UnitParser <VolumeUnit> .TryParse(text, out result));
 }