コード例 #1
0
        private double AsBaseNumericType(MolarFlowUnit unit)
        {
            if (Unit == unit)
            {
                return(_value);
            }

            var baseUnitValue = AsBaseUnit();

            switch (unit)
            {
            case MolarFlowUnit.CentimolePerDay: return((baseUnitValue * 86400) / 1e-2d);

            case MolarFlowUnit.CentimolePerSecond: return((baseUnitValue) / 1e-2d);

            case MolarFlowUnit.DecamolePerDay: return((baseUnitValue * 86400) / 1e1d);

            case MolarFlowUnit.DecamolePerSecond: return((baseUnitValue) / 1e1d);

            case MolarFlowUnit.DecimolePerDay: return((baseUnitValue * 86400) / 1e-1d);

            case MolarFlowUnit.DecimolePerSecond: return((baseUnitValue) / 1e-1d);

            case MolarFlowUnit.HectomolePerDay: return((baseUnitValue * 86400) / 1e2d);

            case MolarFlowUnit.HectomolePerSecond: return((baseUnitValue) / 1e2d);

            case MolarFlowUnit.KilomolePerDay: return((baseUnitValue * 86400) / 1e3d);

            case MolarFlowUnit.KilomolePerHour: return(baseUnitValue * 3.6);

            case MolarFlowUnit.KilomolePerMinute: return(baseUnitValue * 0.06);

            case MolarFlowUnit.KilomolePerSecond: return((baseUnitValue) / 1e3d);

            case MolarFlowUnit.MegamolePerDay: return((baseUnitValue * 86400) / 1e6d);

            case MolarFlowUnit.MicromolePerDay: return((baseUnitValue * 86400) / 1e-6d);

            case MolarFlowUnit.MicromolePerSecond: return((baseUnitValue) / 1e-6d);

            case MolarFlowUnit.MillimolePerDay: return((baseUnitValue * 86400) / 1e-3d);

            case MolarFlowUnit.MillimolePerSecond: return((baseUnitValue) / 1e-3d);

            case MolarFlowUnit.MolePerDay: return(baseUnitValue * 86400);

            case MolarFlowUnit.MolePerHour: return(baseUnitValue * 3600);

            case MolarFlowUnit.MolePerSecond: return(baseUnitValue);

            case MolarFlowUnit.NanomolePerDay: return((baseUnitValue * 86400) / 1e-9d);

            case MolarFlowUnit.NanomolePerSecond: return((baseUnitValue) / 1e-9d);

            default:
                throw new NotImplementedException($"Can not convert {Unit} to {unit}.");
            }
        }
コード例 #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>
        /// <remarks>Value parameter cannot be named 'value' due to constraint when targeting Windows Runtime Component.</remarks>
        /// <exception cref="ArgumentException">If value is NaN or Infinity.</exception>
        private MolarFlow(double value, MolarFlowUnit unit)
        {
            if (unit == MolarFlowUnit.Undefined)
            {
                throw new ArgumentException("The quantity can not be created with an undefined unit.", nameof(unit));
            }

            _value = Guard.EnsureValidNumber(value, nameof(value));
            _unit  = unit;
        }
コード例 #3
0
        /// <summary>
        ///     Convert to the unit representation <paramref name="unit" />.
        /// </summary>
        /// <returns>Value converted to the specified unit.</returns>
        public double As(MolarFlowUnit unit)
        {
            if (Unit == unit)
            {
                return(Convert.ToDouble(Value));
            }

            var converted = AsBaseNumericType(unit);

            return(Convert.ToDouble(converted));
        }
コード例 #4
0
        /// <summary>
        ///     Converts this MolarFlow to another MolarFlow with the unit representation <paramref name="unit" />.
        /// </summary>
        /// <returns>A MolarFlow with the specified unit.</returns>
        public MolarFlow ToUnit(MolarFlowUnit unit)
        {
            var convertedValue = AsBaseNumericType(unit);

            return(new MolarFlow(convertedValue, unit));
        }
コード例 #5
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 MolarFlowUnit unit)
        {
            IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);

            return(UnitParser.Default.TryParse <MolarFlowUnit>(str, provider, out unit));
        }
コード例 #6
0
 public static bool TryParseUnit(string str, out MolarFlowUnit unit)
 {
     return(TryParseUnit(str, null, out unit));
 }
コード例 #7
0
 public static MolarFlow From(double value, MolarFlowUnit fromUnit)
 {
     return(new MolarFlow((double)value, fromUnit));
 }
コード例 #8
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(MolarFlowUnit unit, [CanBeNull] string cultureName)
        {
            IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);

            return(UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider));
        }
コード例 #9
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(MolarFlowUnit unit)
 {
     return(GetAbbreviation(unit, null));
 }