public string ToString(VolumeFlowUnit unit, [CanBeNull] IFormatProvider provider, int significantDigitsAfterRadix)
        {
            double value  = As(unit);
            string format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix);

            return(ToString(unit, provider, format));
        }
        public string ToString(VolumeFlowUnit unit, [CanBeNull] string cultureName, int significantDigitsAfterRadix)
        {
            double value  = As(unit);
            string format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix);

            return(ToString(unit, cultureName, format));
        }
        public static string GetAbbreviation(VolumeFlowUnit unit, [CanBeNull] string cultureName)
        {
            // Windows Runtime Component does not support CultureInfo and IFormatProvider types, so we use culture name for public methods: https://msdn.microsoft.com/en-us/library/br230301.aspx
            IFormatProvider provider = cultureName == null ? UnitSystem.DefaultCulture : new CultureInfo(cultureName);

            return(UnitSystem.GetCached(provider).GetDefaultAbbreviation(unit));
        }
        /// <summary>
        ///     Convert to the unit representation <paramref name="unit" />.
        /// </summary>
        /// <returns>Value converted to the specified unit.</returns>
        public double As(VolumeFlowUnit unit)
        {
            if(Unit == unit)
                return Convert.ToDouble(Value);

            var converted = AsBaseNumericType(unit);
            return Convert.ToDouble(converted);
        }
        /// <summary>
        ///     Creates the quantity with the given numeric value and unit.
        /// </summary>
        /// <param name="numericValue">The numeric value  to contruct this quantity with.</param>
        /// <param name="unit">The unit representation to contruct 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 VolumeFlow(double numericValue, VolumeFlowUnit unit)
        {
            if (unit == VolumeFlowUnit.Undefined)
            {
                throw new ArgumentException("The quantity can not be created with an undefined unit.", nameof(unit));
            }

            _value = Guard.EnsureValidNumber(numericValue, nameof(numericValue));
            _unit  = unit;
        }
        /// <summary>
        ///     Parse a string with one or two quantities of the format "&lt;quantity&gt; &lt;unit&gt;".
        /// </summary>
        /// <param name="str">String to parse. Typically in the form: {number} {unit}</param>
        /// <param name="provider">Format to use when parsing number and unit. Defaults to <see cref="UnitSystem.DefaultCulture" />.</param>
        /// <example>
        ///     Length.Parse("5.5 m", new CultureInfo("en-US"));
        /// </example>
        /// <exception cref="ArgumentNullException">The value of 'str' cannot be null. </exception>
        /// <exception cref="ArgumentException">
        ///     Expected string to have one or two pairs of quantity and unit in the format
        ///     "&lt;quantity&gt; &lt;unit&gt;". Eg. "5.5 m" or "1ft 2in"
        /// </exception>
        /// <exception cref="AmbiguousUnitParseException">
        ///     More than one unit is represented by the specified unit abbreviation.
        ///     Example: Volume.Parse("1 cup") will throw, because it can refer to any of
        ///     <see cref="VolumeUnit.MetricCup" />, <see cref="VolumeUnit.UsLegalCup" /> and <see cref="VolumeUnit.UsCustomaryCup" />.
        /// </exception>
        /// <exception cref="UnitsNetException">
        ///     If anything else goes wrong, typically due to a bug or unhandled case.
        ///     We wrap exceptions in <see cref="UnitsNetException" /> to allow you to distinguish
        ///     Units.NET exceptions from other exceptions.
        /// </exception>
        public static VolumeFlow Parse(string str, [CanBeNull] IFormatProvider provider)
        {
            if (str == null)
            {
                throw new ArgumentNullException(nameof(str));
            }

            provider = provider ?? UnitSystem.DefaultCulture;

            return(QuantityParser.Parse <VolumeFlow, VolumeFlowUnit>(str, provider,
                                                                     delegate(string value, string unit, IFormatProvider formatProvider2)
            {
                double parsedValue = double.Parse(value, formatProvider2);
                VolumeFlowUnit parsedUnit = ParseUnit(unit, formatProvider2);
                return From(parsedValue, parsedUnit);
            }, (x, y) => FromCubicMetersPerSecond(x.CubicMetersPerSecond + y.CubicMetersPerSecond)));
        }
        public string ToString(VolumeFlowUnit unit, [CanBeNull] IFormatProvider provider, [NotNull] string format, [NotNull] params object[] args)
        {
            if (format == null)
            {
                throw new ArgumentNullException(nameof(format));
            }
            if (args == null)
            {
                throw new ArgumentNullException(nameof(args));
            }

            provider = provider ?? UnitSystem.DefaultCulture;

            double value = As(unit);

            object[] formatArgs = UnitFormatter.GetFormatArgs(unit, value, provider, args);
            return(string.Format(provider, format, formatArgs));
        }
        /// <summary>
        ///     Parse a string with one or two quantities of the format "&lt;quantity&gt; &lt;unit&gt;".
        /// </summary>
        /// <param name="str">String to parse. Typically in the form: {number} {unit}</param>
        /// <param name="cultureName">Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to <see cref="UnitSystem" />'s default culture.</param>
        /// <example>
        ///     Length.Parse("5.5 m", new CultureInfo("en-US"));
        /// </example>
        /// <exception cref="ArgumentNullException">The value of 'str' cannot be null. </exception>
        /// <exception cref="ArgumentException">
        ///     Expected string to have one or two pairs of quantity and unit in the format
        ///     "&lt;quantity&gt; &lt;unit&gt;". Eg. "5.5 m" or "1ft 2in"
        /// </exception>
        /// <exception cref="AmbiguousUnitParseException">
        ///     More than one unit is represented by the specified unit abbreviation.
        ///     Example: Volume.Parse("1 cup") will throw, because it can refer to any of
        ///     <see cref="VolumeUnit.MetricCup" />, <see cref="VolumeUnit.UsLegalCup" /> and <see cref="VolumeUnit.UsCustomaryCup" />.
        /// </exception>
        /// <exception cref="UnitsNetException">
        ///     If anything else goes wrong, typically due to a bug or unhandled case.
        ///     We wrap exceptions in <see cref="UnitsNetException" /> to allow you to distinguish
        ///     Units.NET exceptions from other exceptions.
        /// </exception>
        public static VolumeFlow Parse(string str, [CanBeNull] string cultureName)
        {
            if (str == null)
            {
                throw new ArgumentNullException(nameof(str));
            }

            // Windows Runtime Component does not support CultureInfo and IFormatProvider types, so we use culture name for public methods: https://msdn.microsoft.com/en-us/library/br230301.aspx
            IFormatProvider provider = cultureName == null ? UnitSystem.DefaultCulture : new CultureInfo(cultureName);

            return(QuantityParser.Parse <VolumeFlow, VolumeFlowUnit>(str, provider,
                                                                     delegate(string value, string unit, IFormatProvider formatProvider2)
            {
                double parsedValue = double.Parse(value, formatProvider2);
                VolumeFlowUnit parsedUnit = ParseUnit(unit, formatProvider2);
                return From(parsedValue, parsedUnit);
            }, (x, y) => FromCubicMetersPerSecond(x.CubicMetersPerSecond + y.CubicMetersPerSecond)));
        }
        public string ToString(VolumeFlowUnit unit, [CanBeNull] string cultureName, [NotNull] string format, [NotNull] params object[] args)
        {
            if (format == null)
            {
                throw new ArgumentNullException(nameof(format));
            }
            if (args == null)
            {
                throw new ArgumentNullException(nameof(args));
            }

            // Windows Runtime Component does not support CultureInfo and IFormatProvider types, so we use culture name for public methods: https://msdn.microsoft.com/en-us/library/br230301.aspx
            IFormatProvider provider = cultureName == null ? UnitSystem.DefaultCulture : new CultureInfo(cultureName);

            double value = As(unit);

            object[] formatArgs = UnitFormatter.GetFormatArgs(unit, value, provider, args);
            return(string.Format(provider, format, formatArgs));
        }
        private double AsBaseNumericType(VolumeFlowUnit unit)
        {
            if(Unit == unit)
                return _value;

            var baseUnitValue = AsBaseUnit();

            switch(unit)
            {
                case VolumeFlowUnit.CentilitersPerMinute: return (baseUnitValue*60000.00000) / 1e-2d;
                case VolumeFlowUnit.CubicDecimeterPerMinute: return baseUnitValue*60000.00000;
                case VolumeFlowUnit.CubicFootPerHour: return baseUnitValue/7.8657907199999087346816086183876e-6;
                case VolumeFlowUnit.CubicFootPerMinute: return baseUnitValue*2118.88000326;
                case VolumeFlowUnit.CubicFootPerSecond: return baseUnitValue*35.314666721;
                case VolumeFlowUnit.CubicMeterPerHour: return baseUnitValue*3600;
                case VolumeFlowUnit.CubicMeterPerMinute: return baseUnitValue*60;
                case VolumeFlowUnit.CubicMeterPerSecond: return baseUnitValue;
                case VolumeFlowUnit.CubicYardPerHour: return baseUnitValue/2.1237634944E-4;
                case VolumeFlowUnit.CubicYardPerMinute: return baseUnitValue/0.0127425809664;
                case VolumeFlowUnit.CubicYardPerSecond: return baseUnitValue/0.764554857984;
                case VolumeFlowUnit.DecilitersPerMinute: return (baseUnitValue*60000.00000) / 1e-1d;
                case VolumeFlowUnit.KilolitersPerMinute: return (baseUnitValue*60000.00000) / 1e3d;
                case VolumeFlowUnit.LitersPerHour: return baseUnitValue*3600000.000;
                case VolumeFlowUnit.LitersPerMinute: return baseUnitValue*60000.00000;
                case VolumeFlowUnit.LitersPerSecond: return baseUnitValue*1000;
                case VolumeFlowUnit.MicrolitersPerMinute: return (baseUnitValue*60000.00000) / 1e-6d;
                case VolumeFlowUnit.MillilitersPerMinute: return (baseUnitValue*60000.00000) / 1e-3d;
                case VolumeFlowUnit.MillionUsGallonsPerDay: return baseUnitValue*22.824465227;
                case VolumeFlowUnit.NanolitersPerMinute: return (baseUnitValue*60000.00000) / 1e-9d;
                case VolumeFlowUnit.OilBarrelsPerDay: return baseUnitValue/1.8401307283333333333333333333333e-6;
                case VolumeFlowUnit.OilBarrelsPerHour: return baseUnitValue/4.41631375e-5;
                case VolumeFlowUnit.OilBarrelsPerMinute: return baseUnitValue/2.64978825e-3;
                case VolumeFlowUnit.UsGallonsPerHour: return baseUnitValue*951019.38848933424;
                case VolumeFlowUnit.UsGallonsPerMinute: return baseUnitValue*15850.323141489;
                case VolumeFlowUnit.UsGallonsPerSecond: return baseUnitValue*264.1720523581484;
                default:
                    throw new NotImplementedException($"Can not convert {Unit} to {unit}.");
            }
        }
Beispiel #11
0
        private double GetValueAs(VolumeFlowUnit unit)
        {
            if (Unit == unit)
            {
                return(_value);
            }

            var baseUnitValue = GetValueInBaseUnit();

            switch (unit)
            {
            case VolumeFlowUnit.AcreFootPerDay: return(baseUnitValue * 70.0457);

            case VolumeFlowUnit.AcreFootPerHour: return(baseUnitValue * 2.91857);

            case VolumeFlowUnit.AcreFootPerMinute: return(baseUnitValue * 0.0486427916);

            case VolumeFlowUnit.AcreFootPerSecond: return(baseUnitValue * 0.000810713194);

            case VolumeFlowUnit.CentiliterPerDay: return((baseUnitValue * 86400000) / 1e-2d);

            case VolumeFlowUnit.CentiliterPerHour: return((baseUnitValue * 3600000.000) / 1e-2d);

            case VolumeFlowUnit.CentiliterPerMinute: return((baseUnitValue * 60000.00000) / 1e-2d);

            case VolumeFlowUnit.CentiliterPerSecond: return((baseUnitValue * 1000) / 1e-2d);

            case VolumeFlowUnit.CubicCentimeterPerMinute: return(baseUnitValue / 1.6666666666667e-8);

            case VolumeFlowUnit.CubicDecimeterPerMinute: return(baseUnitValue * 60000.00000);

            case VolumeFlowUnit.CubicFootPerHour: return(baseUnitValue / 7.8657907199999087346816086183876e-6);

            case VolumeFlowUnit.CubicFootPerMinute: return(baseUnitValue * 2118.88000326);

            case VolumeFlowUnit.CubicFootPerSecond: return(baseUnitValue * 35.314666721);

            case VolumeFlowUnit.CubicMeterPerDay: return(baseUnitValue * 86400);

            case VolumeFlowUnit.CubicMeterPerHour: return(baseUnitValue * 3600);

            case VolumeFlowUnit.CubicMeterPerMinute: return(baseUnitValue * 60);

            case VolumeFlowUnit.CubicMeterPerSecond: return(baseUnitValue);

            case VolumeFlowUnit.CubicMillimeterPerSecond: return(baseUnitValue / 1e-9);

            case VolumeFlowUnit.CubicYardPerDay: return(baseUnitValue * 113007);

            case VolumeFlowUnit.CubicYardPerHour: return(baseUnitValue / 2.1237634944E-4);

            case VolumeFlowUnit.CubicYardPerMinute: return(baseUnitValue / 0.0127425809664);

            case VolumeFlowUnit.CubicYardPerSecond: return(baseUnitValue / 0.764554857984);

            case VolumeFlowUnit.DeciliterPerDay: return((baseUnitValue * 86400000) / 1e-1d);

            case VolumeFlowUnit.DeciliterPerHour: return((baseUnitValue * 3600000.000) / 1e-1d);

            case VolumeFlowUnit.DeciliterPerMinute: return((baseUnitValue * 60000.00000) / 1e-1d);

            case VolumeFlowUnit.DeciliterPerSecond: return((baseUnitValue * 1000) / 1e-1d);

            case VolumeFlowUnit.KiloliterPerDay: return((baseUnitValue * 86400000) / 1e3d);

            case VolumeFlowUnit.KiloliterPerHour: return((baseUnitValue * 3600000.000) / 1e3d);

            case VolumeFlowUnit.KiloliterPerMinute: return((baseUnitValue * 60000.00000) / 1e3d);

            case VolumeFlowUnit.KiloliterPerSecond: return((baseUnitValue * 1000) / 1e3d);

            case VolumeFlowUnit.KilousGallonPerMinute: return(baseUnitValue * 15.850323141489);

            case VolumeFlowUnit.LiterPerDay: return(baseUnitValue * 86400000);

            case VolumeFlowUnit.LiterPerHour: return(baseUnitValue * 3600000.000);

            case VolumeFlowUnit.LiterPerMinute: return(baseUnitValue * 60000.00000);

            case VolumeFlowUnit.LiterPerSecond: return(baseUnitValue * 1000);

            case VolumeFlowUnit.MegaliterPerDay: return((baseUnitValue * 86400000) / 1e6d);

            case VolumeFlowUnit.MegaukGallonPerSecond: return((baseUnitValue * 219.969) / 1e6d);

            case VolumeFlowUnit.MicroliterPerDay: return((baseUnitValue * 86400000) / 1e-6d);

            case VolumeFlowUnit.MicroliterPerHour: return((baseUnitValue * 3600000.000) / 1e-6d);

            case VolumeFlowUnit.MicroliterPerMinute: return((baseUnitValue * 60000.00000) / 1e-6d);

            case VolumeFlowUnit.MicroliterPerSecond: return((baseUnitValue * 1000) / 1e-6d);

            case VolumeFlowUnit.MilliliterPerDay: return((baseUnitValue * 86400000) / 1e-3d);

            case VolumeFlowUnit.MilliliterPerHour: return((baseUnitValue * 3600000.000) / 1e-3d);

            case VolumeFlowUnit.MilliliterPerMinute: return((baseUnitValue * 60000.00000) / 1e-3d);

            case VolumeFlowUnit.MilliliterPerSecond: return((baseUnitValue * 1000) / 1e-3d);

            case VolumeFlowUnit.MillionUsGallonsPerDay: return(baseUnitValue * 22.824465227);

            case VolumeFlowUnit.NanoliterPerDay: return((baseUnitValue * 86400000) / 1e-9d);

            case VolumeFlowUnit.NanoliterPerHour: return((baseUnitValue * 3600000.000) / 1e-9d);

            case VolumeFlowUnit.NanoliterPerMinute: return((baseUnitValue * 60000.00000) / 1e-9d);

            case VolumeFlowUnit.NanoliterPerSecond: return((baseUnitValue * 1000) / 1e-9d);

            case VolumeFlowUnit.OilBarrelPerDay: return(baseUnitValue / 1.8401307283333333333333333333333e-6);

            case VolumeFlowUnit.OilBarrelPerHour: return(baseUnitValue / 4.41631375e-5);

            case VolumeFlowUnit.OilBarrelPerMinute: return(baseUnitValue / 2.64978825e-3);

            case VolumeFlowUnit.OilBarrelPerSecond: return(baseUnitValue * 6.28981);

            case VolumeFlowUnit.UkGallonPerDay: return(baseUnitValue * 19005304);

            case VolumeFlowUnit.UkGallonPerHour: return(baseUnitValue * 791887.667);

            case VolumeFlowUnit.UkGallonPerMinute: return(baseUnitValue * 13198.2);

            case VolumeFlowUnit.UkGallonPerSecond: return(baseUnitValue * 219.969);

            case VolumeFlowUnit.UsGallonPerDay: return(baseUnitValue * 22824465.227);

            case VolumeFlowUnit.UsGallonPerHour: return(baseUnitValue * 951019.38848933424);

            case VolumeFlowUnit.UsGallonPerMinute: return(baseUnitValue * 15850.323141489);

            case VolumeFlowUnit.UsGallonPerSecond: return(baseUnitValue * 264.1720523581484);

            default:
                throw new NotImplementedException($"Can not convert {Unit} to {unit}.");
            }
        }
Beispiel #12
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 VolumeFlow ToUnit(VolumeFlowUnit unit)
        {
            var convertedValue = GetValueAs(unit);

            return(new VolumeFlow(convertedValue, unit));
        }
Beispiel #13
0
 /// <summary>
 ///     Convert to the unit representation <paramref name="unit" />.
 /// </summary>
 /// <returns>Value converted to the specified unit.</returns>
 public double As(VolumeFlowUnit unit) => GetValueAs(unit);
Beispiel #14
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 VolumeFlow(double value, VolumeFlowUnit unit)
 {
     _value = value;
     _unit  = unit;
 }
        public static VolumeFlow From(QuantityValue value, VolumeFlowUnit fromUnit)
#endif
        {
            return(new VolumeFlow((double)value, fromUnit));
        }
 VolumeFlow(double numericValue, VolumeFlowUnit unit)
 {
     _value = numericValue;
     _unit  = unit;
 }
 public static bool TryParseUnit(string str, out VolumeFlowUnit unit)
 {
     return(TryParseUnit(str, null, out unit));
 }
        /// <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(VolumeFlowUnit unit, [CanBeNull] string cultureName)
        {
            IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);

            return(UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider));
        }
 /// <summary>
 ///     Get string representation of value and unit. Using current UI culture and two significant digits after radix.
 /// </summary>
 /// <param name="unit">Unit representation to use.</param>
 /// <returns>String representation.</returns>
 public string ToString(VolumeFlowUnit unit)
 {
     return(ToString(unit, null, 2));
 }
 /// <summary>
 ///     Get string representation of value and unit. Using two significant digits after radix.
 /// </summary>
 /// <param name="unit">Unit representation to use.</param>
 /// <param name="cultureName">Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to <see cref="UnitSystem" />'s default culture.</param>
 /// <returns>String representation.</returns>
 public string ToString(VolumeFlowUnit unit, [CanBeNull] string cultureName)
 {
     return(ToString(unit, cultureName, 2));
 }
 /// <summary>
 ///     Dynamically convert from value and unit enum <see cref="VolumeFlowUnit" /> to <see cref="VolumeFlow" />.
 /// </summary>
 /// <param name="value">Value to convert from.</param>
 /// <param name="fromUnit">Unit to convert from.</param>
 /// <returns>VolumeFlow unit value.</returns>
 public static VolumeFlow?From(QuantityValue?value, VolumeFlowUnit fromUnit)
 {
     return(value.HasValue ? new VolumeFlow((double)value.Value, fromUnit) : default(VolumeFlow?));
 }
Beispiel #22
0
 public static void HasConversion(this PropertyBuilder <VolumeFlow> propertyBuilder, VolumeFlowUnit unit) =>
 propertyBuilder.HasConversion(v => v.As(unit), v => new VolumeFlow(v, unit));
 /// <summary>
 ///     Get unit abbreviation string.
 /// </summary>
 /// <param name="unit">Unit to get abbreviation for.</param>
 /// <returns>Unit abbreviation string.</returns>
 public static string GetAbbreviation(VolumeFlowUnit unit)
 {
     return(GetAbbreviation(unit, null));
 }
 public static VolumeFlow From(double value, VolumeFlowUnit fromUnit)
 public static VolumeFlow From(double value, VolumeFlowUnit fromUnit)
 {
     return(new VolumeFlow((double)value, fromUnit));
 }
        public static string GetAbbreviation(VolumeFlowUnit unit, [CanBeNull] IFormatProvider provider)
        {
            provider = provider ?? UnitSystem.DefaultCulture;

            return(UnitSystem.GetCached(provider).GetDefaultAbbreviation(unit));
        }
        /// <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 VolumeFlowUnit unit)
        {
            IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);

            return(UnitParser.Default.TryParse <VolumeFlowUnit>(str, provider, out unit));
        }
 /// <summary>
 ///     Get string representation of value and unit. Using two significant digits after radix.
 /// </summary>
 /// <param name="unit">Unit representation to use.</param>
 /// <param name="provider">Format to use for localization and number formatting. Defaults to <see cref="UnitSystem.DefaultCulture" />.</param>
 /// <returns>String representation.</returns>
 public string ToString(VolumeFlowUnit unit, [CanBeNull] IFormatProvider provider)
 {
     return(ToString(unit, provider, 2));
 }
        /// <summary>
        ///     Converts this VolumeFlow to another VolumeFlow with the unit representation <paramref name="unit" />.
        /// </summary>
        /// <returns>A VolumeFlow with the specified unit.</returns>
        public VolumeFlow ToUnit(VolumeFlowUnit unit)
        {
            var convertedValue = AsBaseNumericType(unit);

            return(new VolumeFlow(convertedValue, unit));
        }
        public static string GetAbbreviation(
            VolumeFlowUnit unit,
#if WINDOWS_UWP
            [CanBeNull] string cultureName)