Exemple #1
0
        private double AsBaseNumericType(StandardVolumeFlowUnit unit)
        {
            if (Unit == unit)
            {
                return(_value);
            }

            var baseUnitValue = AsBaseUnit();

            switch (unit)
            {
            case StandardVolumeFlowUnit.StandardCubicCentimeterPerMinute: return(baseUnitValue * 6e7);

            case StandardVolumeFlowUnit.StandardCubicFootPerHour: return(baseUnitValue / 7.8657907199999087346816086183876e-6);

            case StandardVolumeFlowUnit.StandardCubicFootPerMinute: return(baseUnitValue * 2118.88000326);

            case StandardVolumeFlowUnit.StandardCubicFootPerSecond: return(baseUnitValue * 35.314666721);

            case StandardVolumeFlowUnit.StandardCubicMeterPerDay: return(baseUnitValue * 86400);

            case StandardVolumeFlowUnit.StandardCubicMeterPerHour: return(baseUnitValue * 3600);

            case StandardVolumeFlowUnit.StandardCubicMeterPerMinute: return(baseUnitValue * 60);

            case StandardVolumeFlowUnit.StandardCubicMeterPerSecond: return(baseUnitValue);

            case StandardVolumeFlowUnit.StandardLiterPerMinute: return(baseUnitValue * 60000);

            default:
                throw new NotImplementedException($"Can not convert {Unit} to {unit}.");
            }
        }
Exemple #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 StandardVolumeFlow(double value, StandardVolumeFlowUnit unit)
        {
            if (unit == StandardVolumeFlowUnit.Undefined)
            {
                throw new ArgumentException("The quantity can not be created with an undefined unit.", nameof(unit));
            }

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

            var converted = AsBaseNumericType(unit);

            return(Convert.ToDouble(converted));
        }
// ReSharper restore VirtualMemberNeverOverriden.Global

        protected (double UnitsInBaseUnit, double Tolerence) GetConversionFactor(StandardVolumeFlowUnit unit)
        {
            return(unit switch
            {
                StandardVolumeFlowUnit.StandardCubicCentimeterPerMinute => (StandardCubicCentimetersPerMinuteInOneStandardCubicMeterPerSecond, StandardCubicCentimetersPerMinuteTolerance),
                StandardVolumeFlowUnit.StandardCubicFootPerHour => (StandardCubicFeetPerHourInOneStandardCubicMeterPerSecond, StandardCubicFeetPerHourTolerance),
                StandardVolumeFlowUnit.StandardCubicFootPerMinute => (StandardCubicFeetPerMinuteInOneStandardCubicMeterPerSecond, StandardCubicFeetPerMinuteTolerance),
                StandardVolumeFlowUnit.StandardCubicFootPerSecond => (StandardCubicFeetPerSecondInOneStandardCubicMeterPerSecond, StandardCubicFeetPerSecondTolerance),
                StandardVolumeFlowUnit.StandardCubicMeterPerDay => (StandardCubicMetersPerDayInOneStandardCubicMeterPerSecond, StandardCubicMetersPerDayTolerance),
                StandardVolumeFlowUnit.StandardCubicMeterPerHour => (StandardCubicMetersPerHourInOneStandardCubicMeterPerSecond, StandardCubicMetersPerHourTolerance),
                StandardVolumeFlowUnit.StandardCubicMeterPerMinute => (StandardCubicMetersPerMinuteInOneStandardCubicMeterPerSecond, StandardCubicMetersPerMinuteTolerance),
                StandardVolumeFlowUnit.StandardCubicMeterPerSecond => (StandardCubicMetersPerSecondInOneStandardCubicMeterPerSecond, StandardCubicMetersPerSecondTolerance),
                StandardVolumeFlowUnit.StandardLiterPerMinute => (StandardLitersPerMinuteInOneStandardCubicMeterPerSecond, StandardLitersPerMinuteTolerance),
                _ => throw new NotSupportedException()
            });
Exemple #5
0
        /// <summary>
        ///     Converts this StandardVolumeFlow to another StandardVolumeFlow with the unit representation <paramref name="unit" />.
        /// </summary>
        /// <returns>A StandardVolumeFlow with the specified unit.</returns>
        public StandardVolumeFlow ToUnit(StandardVolumeFlowUnit unit)
        {
            var convertedValue = AsBaseNumericType(unit);

            return(new StandardVolumeFlow(convertedValue, unit));
        }
Exemple #6
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 StandardVolumeFlowUnit unit)
        {
            IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);

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

            return(UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider));
        }
Exemple #10
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(StandardVolumeFlowUnit unit)
 {
     return(GetAbbreviation(unit, null));
 }
 /// <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 StandardVolumeFlow(double value, StandardVolumeFlowUnit unit)
 {
     _value = value;
     _unit  = unit;
 }
        /// <summary>
        ///     Converts this Duration to another Duration with the unit representation <paramref name="unit" />.
        /// </summary>
        /// <returns>A Duration with the specified unit.</returns>
        public StandardVolumeFlow ToUnit(StandardVolumeFlowUnit unit)
        {
            var convertedValue = GetValueAs(unit);

            return(new StandardVolumeFlow(convertedValue, unit));
        }
 /// <summary>
 ///     Convert to the unit representation <paramref name="unit" />.
 /// </summary>
 /// <returns>Value converted to the specified unit.</returns>
 public double As(StandardVolumeFlowUnit unit) => GetValueAs(unit);