SpecificEnergy(double numericValue, SpecificEnergyUnit unit)
 {
     _value = numericValue;
     _unit  = unit;
 }
 public static SpecificEnergy From(double value, SpecificEnergyUnit fromUnit)
Exemple #3
0
 public static string GetAbbreviation(SpecificEnergyUnit unit, [CanBeNull] Culture culture)
 {
     return(UnitSystem.GetCached(culture).GetDefaultAbbreviation(unit));
 }
 public ConstructorForValueAndUnitTestData(double value, SpecificEnergyUnit unit, double expectedJoulesPerKilogram)
     : base(new SpecificEnergy((number)value, unit), new SpecificEnergy((number)expectedJoulesPerKilogram))
 {
 }
Exemple #5
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 SpecificEnergy(double value, SpecificEnergyUnit unit)
 {
     _value = value;
     _unit  = unit;
 }
 /// <summary>
 ///     Convert to the unit representation <paramref name="unit" />.
 /// </summary>
 /// <returns>Value converted to the specified unit.</returns>
 public double As(SpecificEnergyUnit unit) => GetValueAs(unit);
        /// <summary>
        ///     Converts this SpecificEnergy to another SpecificEnergy with the unit representation <paramref name="unit" />.
        /// </summary>
        /// <returns>A SpecificEnergy with the specified unit.</returns>
        public SpecificEnergy ToUnit(SpecificEnergyUnit unit)
        {
            var convertedValue = AsBaseNumericType(unit);

            return(new SpecificEnergy(convertedValue, unit));
        }
        public static string GetAbbreviation(
            SpecificEnergyUnit unit,
#if WINDOWS_UWP
            [CanBeNull] string cultureName)
 public static bool TryParseUnit(string str, out SpecificEnergyUnit unit)
 {
     return(TryParseUnit(str, null, out 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 SpecificEnergyUnit unit)
        {
            IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);

            return(UnitParser.Default.TryParse <SpecificEnergyUnit>(str, provider, 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(SpecificEnergyUnit unit, [CanBeNull] string cultureName)
        {
            IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);

            return(UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider));
        }
Exemple #12
0
 private SpecificEnergyJsonConverter(SpecificEnergyUnit unit)
 {
     this.unit = unit;
 }
Exemple #13
0
 /// <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="culture">Culture to use for localization and number formatting.</param>
 /// <returns>String representation.</returns>
 public string ToString(SpecificEnergyUnit unit, [CanBeNull] Culture culture)
 {
     return(ToString(unit, culture, 2));
 }
Exemple #14
0
        public static SpecificEnergy From(QuantityValue value, SpecificEnergyUnit fromUnit)
#endif
        {
            return(new SpecificEnergy((double)value, fromUnit));
        }
 /// <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(SpecificEnergyUnit unit)
 {
     return(ToString(unit, null, 2));
 }
Exemple #16
0
 public static string GetAbbreviation(SpecificEnergyUnit unit)
 {
     return(GetAbbreviation(unit, null));
 }
 /// <summary>
 ///     Dynamically convert from value and unit enum <see cref="SpecificEnergyUnit" /> to <see cref="SpecificEnergy" />.
 /// </summary>
 /// <param name="value">Value to convert from.</param>
 /// <param name="fromUnit">Unit to convert from.</param>
 /// <returns>SpecificEnergy unit value.</returns>
 public static SpecificEnergy?From(QuantityValue?value, SpecificEnergyUnit fromUnit)
 {
     return(value.HasValue ? new SpecificEnergy((double)value.Value, fromUnit) : default(SpecificEnergy?));
 }
Exemple #18
0
        private double GetValueAs(SpecificEnergyUnit unit)
        {
            if (Unit == unit)
            {
                return(_value);
            }

            var baseUnitValue = GetValueInBaseUnit();

            switch (unit)
            {
            case SpecificEnergyUnit.BtuPerPound: return(baseUnitValue / 2326.000075362);

            case SpecificEnergyUnit.CaloriePerGram: return(baseUnitValue / 4.184e3);

            case SpecificEnergyUnit.GigawattDayPerKilogram: return((baseUnitValue / (24 * 3.6e3)) / 1e9d);

            case SpecificEnergyUnit.GigawattDayPerShortTon: return((baseUnitValue / ((24 * 3.6e3) / 9.0718474e2)) / 1e9d);

            case SpecificEnergyUnit.GigawattDayPerTonne: return((baseUnitValue / ((24 * 3.6e3) / 1e3)) / 1e9d);

            case SpecificEnergyUnit.GigawattHourPerKilogram: return((baseUnitValue / 3.6e3) / 1e9d);

            case SpecificEnergyUnit.JoulePerKilogram: return(baseUnitValue);

            case SpecificEnergyUnit.KilocaloriePerGram: return((baseUnitValue / 4.184e3) / 1e3d);

            case SpecificEnergyUnit.KilojoulePerKilogram: return((baseUnitValue) / 1e3d);

            case SpecificEnergyUnit.KilowattDayPerKilogram: return((baseUnitValue / (24 * 3.6e3)) / 1e3d);

            case SpecificEnergyUnit.KilowattDayPerShortTon: return((baseUnitValue / ((24 * 3.6e3) / 9.0718474e2)) / 1e3d);

            case SpecificEnergyUnit.KilowattDayPerTonne: return((baseUnitValue / ((24 * 3.6e3) / 1e3)) / 1e3d);

            case SpecificEnergyUnit.KilowattHourPerKilogram: return((baseUnitValue / 3.6e3) / 1e3d);

            case SpecificEnergyUnit.MegajoulePerKilogram: return((baseUnitValue) / 1e6d);

            case SpecificEnergyUnit.MegawattDayPerKilogram: return((baseUnitValue / (24 * 3.6e3)) / 1e6d);

            case SpecificEnergyUnit.MegawattDayPerShortTon: return((baseUnitValue / ((24 * 3.6e3) / 9.0718474e2)) / 1e6d);

            case SpecificEnergyUnit.MegawattDayPerTonne: return((baseUnitValue / ((24 * 3.6e3) / 1e3)) / 1e6d);

            case SpecificEnergyUnit.MegawattHourPerKilogram: return((baseUnitValue / 3.6e3) / 1e6d);

            case SpecificEnergyUnit.TerawattDayPerKilogram: return((baseUnitValue / (24 * 3.6e3)) / 1e12d);

            case SpecificEnergyUnit.TerawattDayPerShortTon: return((baseUnitValue / ((24 * 3.6e3) / 9.0718474e2)) / 1e12d);

            case SpecificEnergyUnit.TerawattDayPerTonne: return((baseUnitValue / ((24 * 3.6e3) / 1e3)) / 1e12d);

            case SpecificEnergyUnit.WattDayPerKilogram: return(baseUnitValue / (24 * 3.6e3));

            case SpecificEnergyUnit.WattDayPerShortTon: return(baseUnitValue / ((24 * 3.6e3) / 9.0718474e2));

            case SpecificEnergyUnit.WattDayPerTonne: return(baseUnitValue / ((24 * 3.6e3) / 1e3));

            case SpecificEnergyUnit.WattHourPerKilogram: return(baseUnitValue / 3.6e3);

            default:
                throw new NotImplementedException($"Can not convert {Unit} to {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(SpecificEnergyUnit unit, [CanBeNull] IFormatProvider provider)
 {
     return(ToString(unit, provider, 2));
 }
 /// <summary>
 ///     Dynamically convert from value and unit enum <see cref="SpecificEnergyUnit" /> to <see cref="SpecificEnergy" />.
 /// </summary>
 /// <param name="value">Value to convert from.</param>
 /// <param name="fromUnit">Unit to convert from.</param>
 /// <returns>SpecificEnergy unit value.</returns>
 public static SpecificEnergy From(double value, SpecificEnergyUnit fromUnit)
 {
     return(new SpecificEnergy(value, fromUnit));
 }
Exemple #21
0
 public static void HasConversion(this PropertyBuilder <SpecificEnergy> propertyBuilder, SpecificEnergyUnit unit) =>
 propertyBuilder.HasConversion(v => v.As(unit), v => new SpecificEnergy(v, 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 SpecificEnergy ToUnit(SpecificEnergyUnit unit)
        {
            var convertedValue = GetValueAs(unit);

            return(new SpecificEnergy(convertedValue, unit));
        }
 protected static string CreateSuffix(SymbolFormat format, SpecificEnergyUnit unit)
 {
     return default(SpecificEnergy).ToString(unit, format).Trim('0');
 }