public static string GetAbbreviation(ThermalConductivityUnit 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));
        }
Esempio n. 2
0
        //HeatFluxDensityUnit heatTransferCoefficient;
        //ForceUnit force;
        //SurfaceTensionUnit surfaceTension;

        public UnitSystem(TemperatureUnit temperature, PressureUnit pressure, MassFlowRateUnit massFlowRate,
                          VolumeFlowRateUnit volumeFlowRate, MoistureContentUnit moistureContent,
                          RatioUnit relativeHumidity, SpecificEnergyUnit enthalpy,
                          SpecificHeatUnit specificHeat, EnergyUnit energy, PowerUnit power, DensityUnit density,
                          DynamicViscosityUnit dynamicViscosity, KinematicViscosityUnit kinematicViscosity,
                          ThermalConductivityUnit conductivity, DiffusivityUnit diffusivity, MassUnit mass,
                          LengthUnit length, AreaUnit area, VolumeUnit volume, TimeUnit Time, string name) //ep
        {
            this.temperature        = temperature;
            this.pressure           = pressure;
            this.massFlowRate       = massFlowRate;
            this.volumeFlowRate     = volumeFlowRate;
            this.moistureContent    = moistureContent;
            this.relativeHumidity   = relativeHumidity;
            this.enthalpy           = enthalpy;
            this.specificHeat       = specificHeat;
            this.energy             = energy;
            this.power              = power;
            this.density            = density;
            this.dynamicViscosity   = dynamicViscosity;
            this.kinematicViscosity = kinematicViscosity;
            this.conductivity       = conductivity;
            this.diffusivity        = diffusivity;
            this.mass     = mass;
            this.length   = length;
            this.area     = area;
            this.volume   = volume;
            this.time     = time;
            this.Name     = name;  //ep
            this.readOnly = false; //ep
        }
Esempio n. 3
0
 public UnitSystem()
 {
     this.temperature        = TemperatureUnit.Celsius;
     this.pressure           = PressureUnit.Pascal;
     this.massFlowRate       = MassFlowRateUnit.KgPerSec;
     this.volumeFlowRate     = VolumeFlowRateUnit.CubicMeterPerSec;
     this.moistureContent    = MoistureContentUnit.KgPerKg;
     this.relativeHumidity   = RatioUnit.Percent;
     this.enthalpy           = SpecificEnergyUnit.JoulePerKg;
     this.specificHeat       = SpecificHeatUnit.JoulePerKgKelvin;
     this.energy             = EnergyUnit.Joule;
     this.power              = PowerUnit.JoulePerSec;
     this.density            = DensityUnit.KgPerCubicMeter;
     this.dynamicViscosity   = DynamicViscosityUnit.PascalSecond;
     this.kinematicViscosity = KinematicViscosityUnit.SquareMeterPerSec;
     this.conductivity       = ThermalConductivityUnit.WattPerMeterKelvin;
     this.diffusivity        = DiffusivityUnit.SquareMeterPerSec;
     this.mass     = MassUnit.Kilogram;
     this.length   = LengthUnit.Meter;
     this.area     = AreaUnit.SquareMeter;
     this.volume   = VolumeUnit.CubicMeter;
     this.time     = TimeUnit.Second;
     this.Name     = "SI"; //ep
     this.readOnly = true;
 }
Esempio n. 4
0
        public string ToString(ThermalConductivityUnit unit, [CanBeNull] IFormatProvider provider, int significantDigitsAfterRadix)
        {
            double value  = As(unit);
            string format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix);

            return(ToString(unit, provider, format));
        }
Esempio n. 5
0
// ReSharper restore VirtualMemberNeverOverriden.Global

        protected (double UnitsInBaseUnit, double Tolerence) GetConversionFactor(ThermalConductivityUnit unit)
        {
            return(unit switch
            {
                ThermalConductivityUnit.BtuPerHourFootFahrenheit => (BtusPerHourFootFahrenheitInOneWattPerMeterKelvin, BtusPerHourFootFahrenheitTolerance),
                ThermalConductivityUnit.WattPerMeterKelvin => (WattsPerMeterKelvinInOneWattPerMeterKelvin, WattsPerMeterKelvinTolerance),
                _ => throw new NotSupportedException()
            });
Esempio n. 6
0
        // Windows Runtime Component does not support nullable types (double?): https://msdn.microsoft.com/en-us/library/br230301.aspx
#if !WINDOWS_UWP
        /// <summary>
        ///     Dynamically convert from value and unit enum <see cref="ThermalConductivityUnit" /> to <see cref="ThermalConductivity" />.
        /// </summary>
        /// <param name="value">Value to convert from.</param>
        /// <param name="fromUnit">Unit to convert from.</param>
        /// <returns>ThermalConductivity unit value.</returns>
        public static ThermalConductivity?From(QuantityValue?value, ThermalConductivityUnit fromUnit)
        {
            if (!value.HasValue)
            {
                return(null);
            }

            return(new ThermalConductivity((double)value.Value, fromUnit));
        }
Esempio n. 7
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 ThermalConductivity(decimal value, ThermalConductivityUnit unit)
        {
            if (unit == ThermalConductivityUnit.Undefined)
            {
                throw new ArgumentException("The quantity can not be created with an undefined unit.", nameof(unit));
            }

            _value = value;
            _unit  = unit;
        }
Esempio n. 8
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 ThermalConductivity(double value, ThermalConductivityUnit unit)
        {
            if (unit == ThermalConductivityUnit.Undefined)
            {
                throw new ArgumentException("The quantity can not be created with an undefined unit.", nameof(unit));
            }

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

            var converted = AsBaseNumericType(unit);

            return(Convert.ToDouble(converted));
        }
        /// <summary>
        ///     Convert to the unit representation <paramref name="unit" />.
        /// </summary>
        /// <returns>Value in new unit if successful, exception otherwise.</returns>
        /// <exception cref="NotImplementedException">If conversion was not successful.</exception>
        public double As(ThermalConductivityUnit unit)
        {
            switch (unit)
            {
            case ThermalConductivityUnit.WattPerMeterKelvin:
                return(WattsPerMeterKelvin);

            default:
                throw new NotImplementedException("unit: " + unit);
            }
        }
        public static ThermalConductivity From(QuantityValue value, ThermalConductivityUnit fromUnit)
#endif
        {
            switch (fromUnit)
            {
            case ThermalConductivityUnit.WattPerMeterKelvin:
                return(FromWattsPerMeterKelvin(value));

            default:
                throw new NotImplementedException("fromUnit: " + fromUnit);
            }
        }
        // Windows Runtime Component does not support nullable types (double?): https://msdn.microsoft.com/en-us/library/br230301.aspx
#if !WINDOWS_UWP
        /// <summary>
        ///     Dynamically convert from value and unit enum <see cref="ThermalConductivityUnit" /> to <see cref="ThermalConductivity" />.
        /// </summary>
        /// <param name="value">Value to convert from.</param>
        /// <param name="fromUnit">Unit to convert from.</param>
        /// <returns>ThermalConductivity unit value.</returns>
        public static ThermalConductivity?From(QuantityValue?value, ThermalConductivityUnit fromUnit)
        {
            if (!value.HasValue)
            {
                return(null);
            }
            switch (fromUnit)
            {
            case ThermalConductivityUnit.WattPerMeterKelvin:
                return(FromWattsPerMeterKelvin(value.Value));

            default:
                throw new NotImplementedException("fromUnit: " + fromUnit);
            }
        }
Esempio n. 13
0
        /// <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 ThermalConductivity Parse(string str, [CanBeNull] IFormatProvider provider)
        {
            if (str == null)
            {
                throw new ArgumentNullException(nameof(str));
            }

            provider = provider ?? UnitSystem.DefaultCulture;

            return(QuantityParser.Parse <ThermalConductivity, ThermalConductivityUnit>(str, provider,
                                                                                       delegate(string value, string unit, IFormatProvider formatProvider2)
            {
                double parsedValue = double.Parse(value, formatProvider2);
                ThermalConductivityUnit parsedUnit = ParseUnit(unit, formatProvider2);
                return From(parsedValue, parsedUnit);
            }, (x, y) => FromWattsPerMeterKelvin(x.WattsPerMeterKelvin + y.WattsPerMeterKelvin)));
        }
        /// <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 ThermalConductivity 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 <ThermalConductivity, ThermalConductivityUnit>(str, provider,
                                                                                       delegate(string value, string unit, IFormatProvider formatProvider2)
            {
                double parsedValue = double.Parse(value, formatProvider2);
                ThermalConductivityUnit parsedUnit = ParseUnit(unit, formatProvider2);
                return From(parsedValue, parsedUnit);
            }, (x, y) => FromWattsPerMeterKelvin(x.WattsPerMeterKelvin + y.WattsPerMeterKelvin)));
        }
Esempio n. 15
0
        public string ToString(ThermalConductivityUnit 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));
        }
Esempio n. 16
0
        private double AsBaseNumericType(ThermalConductivityUnit unit)
        {
            if (Unit == unit)
            {
                return(_value);
            }

            var baseUnitValue = AsBaseUnit();

            switch (unit)
            {
            case ThermalConductivityUnit.BtuPerHourFootFahrenheit: return(baseUnitValue / 1.73073467);

            case ThermalConductivityUnit.WattPerMeterKelvin: return(baseUnitValue);

            default:
                throw new NotImplementedException($"Can not convert {Unit} to {unit}.");
            }
        }
        public string ToString(ThermalConductivityUnit 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));
        }
        /// <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="culture">Format to use when parsing number and unit. If it is null, it defaults to <see cref="NumberFormatInfo.CurrentInfo"/> for parsing the number and <see cref="CultureInfo.CurrentUICulture"/> for parsing the unit abbreviation by culture/language.</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 ThermalConductivity Parse(string str, [CanBeNull] Culture culture)
        {
            if (str == null)
            {
                throw new ArgumentNullException("str");
            }

            // Windows Runtime Component does not support CultureInfo type, so use culture name string for public methods instead: https://msdn.microsoft.com/en-us/library/br230301.aspx
#if WINDOWS_UWP
            IFormatProvider formatProvider = culture == null ? null : new CultureInfo(culture);
#else
            IFormatProvider formatProvider = culture;
#endif
            return(QuantityParser.Parse <ThermalConductivity, ThermalConductivityUnit>(str, formatProvider,
                                                                                       delegate(string value, string unit, IFormatProvider formatProvider2)
            {
                double parsedValue = double.Parse(value, formatProvider2);
                ThermalConductivityUnit parsedUnit = ParseUnit(unit, formatProvider2);
                return From(parsedValue, parsedUnit);
            }, (x, y) => FromWattsPerMeterKelvin(x.WattsPerMeterKelvin + y.WattsPerMeterKelvin)));
        }
        public string ToString(ThermalConductivityUnit unit, [CanBeNull] Culture culture, [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 type, so use culture name string for public methods instead: https://msdn.microsoft.com/en-us/library/br230301.aspx
#if WINDOWS_UWP
            IFormatProvider formatProvider = culture == null ? null : new CultureInfo(culture);
#else
            IFormatProvider formatProvider = culture;
#endif
            double   value      = As(unit);
            object[] formatArgs = UnitFormatter.GetFormatArgs(unit, value, formatProvider, args);
            return(string.Format(formatProvider, format, formatArgs));
        }
Esempio n. 20
0
 /// <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(ThermalConductivityUnit unit)
 {
     return(ToString(unit, null, 2));
 }
Esempio n. 21
0
        /// <summary>
        ///     Converts this ThermalConductivity to another ThermalConductivity with the unit representation <paramref name="unit" />.
        /// </summary>
        /// <returns>A ThermalConductivity with the specified unit.</returns>
        public ThermalConductivity ToUnit(ThermalConductivityUnit unit)
        {
            var convertedValue = AsBaseNumericType(unit);

            return(new ThermalConductivity(convertedValue, unit));
        }
Esempio n. 22
0
 public static string GetAbbreviation(ThermalConductivityUnit unit)
 {
     return(GetAbbreviation(unit, null));
 }
Esempio n. 23
0
        public static ThermalConductivity From(QuantityValue value, ThermalConductivityUnit fromUnit)
#endif
        {
            return(new ThermalConductivity((double)value, fromUnit));
        }
Esempio n. 24
0
 public static ThermalConductivity From(double value, ThermalConductivityUnit fromUnit)
Esempio n. 25
0
 ThermalConductivity(double numericValue, ThermalConductivityUnit unit)
 {
     _value = numericValue;
     _unit  = unit;
 }
Esempio n. 26
0
        public static string GetAbbreviation(
            ThermalConductivityUnit unit,
#if WINDOWS_UWP
            [CanBeNull] string cultureName)
Esempio n. 27
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 ThermalConductivity(double value, ThermalConductivityUnit unit)
 {
     _value = value;
     _unit  = unit;
 }
Esempio n. 28
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 ThermalConductivity ToUnit(ThermalConductivityUnit unit)
        {
            var convertedValue = GetValueAs(unit);

            return(new ThermalConductivity(convertedValue, unit));
        }
Esempio n. 29
0
 /// <summary>
 ///     Convert to the unit representation <paramref name="unit" />.
 /// </summary>
 /// <returns>Value converted to the specified unit.</returns>
 public double As(ThermalConductivityUnit unit) => GetValueAs(unit);
Esempio n. 30
0
 /// <summary>
 ///     Dynamically convert from value and unit enum <see cref="ThermalConductivityUnit" /> to <see cref="ThermalConductivity" />.
 /// </summary>
 /// <param name="value">Value to convert from.</param>
 /// <param name="fromUnit">Unit to convert from.</param>
 /// <returns>ThermalConductivity unit value.</returns>
 public static ThermalConductivity From(double value, ThermalConductivityUnit fromUnit)
 {
     return(new ThermalConductivity(value, fromUnit));
 }