Esempio n. 1
0
        /// <summary>
        ///     Get unit abbreviation string.
        /// </summary>
        /// <param name="unit">Unit to get abbreviation for.</param>
        /// <returns>Unit abbreviation string.</returns>
        /// <param name="cultureName">Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to <see cref="GlobalConfiguration.DefaultCulture" /> if null.</param>
        public static string GetAbbreviation(VolumePerLengthUnit unit, [CanBeNull] string cultureName)
        {
            IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);

            return(UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider));
        }
Esempio n. 2
0
 /// <summary>
 ///     Creates the quantity with the given numeric value and unit.
 /// </summary>
 /// <param name="value">The numeric value to construct this quantity with.</param>
 /// <param name="unit">The unit representation to construct this quantity with.</param>
 /// <exception cref="ArgumentException">If value is NaN or Infinity.</exception>
 public VolumePerLength(double value, VolumePerLengthUnit unit)
 {
     _value = value;
     _unit  = unit;
 }
Esempio n. 3
0
 /// <summary>
 ///     Get unit abbreviation string.
 /// </summary>
 /// <param name="unit">Unit to get abbreviation for.</param>
 /// <returns>Unit abbreviation string.</returns>
 public static string GetAbbreviation(VolumePerLengthUnit unit)
 {
     return(GetAbbreviation(unit, null));
 }
Esempio n. 4
0
 /// <summary>
 ///     Convert to the unit representation <paramref name="unit" />.
 /// </summary>
 /// <returns>Value converted to the specified unit.</returns>
 public double As(VolumePerLengthUnit unit) => GetValueAs(unit);
Esempio n. 5
0
        /// <summary>
        ///     Converts this Duration to another Duration with the unit representation <paramref name="unit" />.
        /// </summary>
        /// <returns>A Duration with the specified unit.</returns>
        public VolumePerLength ToUnit(VolumePerLengthUnit unit)
        {
            var convertedValue = GetValueAs(unit);

            return(new VolumePerLength(convertedValue, unit));
        }
Esempio n. 6
0
 /// <summary>
 ///     Dynamically convert from value and unit enum <see cref="VolumePerLengthUnit" /> to <see cref="VolumePerLength" />.
 /// </summary>
 /// <param name="value">Value to convert from.</param>
 /// <param name="fromUnit">Unit to convert from.</param>
 /// <returns>VolumePerLength unit value.</returns>
 public static VolumePerLength From(double value, VolumePerLengthUnit fromUnit)
 {
     return(new VolumePerLength(value, fromUnit));
 }
Esempio n. 7
0
        /// <summary>
        ///     Converts this VolumePerLength to another VolumePerLength with the unit representation <paramref name="unit" />.
        /// </summary>
        /// <returns>A VolumePerLength with the specified unit.</returns>
        public VolumePerLength ToUnit(VolumePerLengthUnit unit)
        {
            var convertedValue = AsBaseNumericType(unit);

            return(new VolumePerLength(convertedValue, unit));
        }
Esempio n. 8
0
        /// <summary>
        ///     Parse a unit string.
        /// </summary>
        /// <param name="str">String to parse. Typically in the form: {number} {unit}</param>
        /// <param name="unit">The parsed unit if successful.</param>
        /// <returns>True if successful, otherwise false.</returns>
        /// <example>
        ///     Length.TryParseUnit("m", new CultureInfo("en-US"));
        /// </example>
        /// <param name="cultureName">Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to <see cref="GlobalConfiguration.DefaultCulture" /> if null.</param>
        public static bool TryParseUnit(string str, [CanBeNull] string cultureName, out VolumePerLengthUnit unit)
        {
            IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);

            return(UnitParser.Default.TryParse <VolumePerLengthUnit>(str, provider, out unit));
        }
Esempio n. 9
0
 public static bool TryParseUnit(string str, out VolumePerLengthUnit unit)
 {
     return(TryParseUnit(str, null, out unit));
 }
Esempio n. 10
0
 public static void HasConversion(this PropertyBuilder <VolumePerLength> propertyBuilder, VolumePerLengthUnit unit) =>
 propertyBuilder.HasConversion(v => v.As(unit), v => new VolumePerLength(v, unit));