Пример #1
0
        private double AsBaseNumericType(MassFluxUnit unit)
        {
            if (Unit == unit)
            {
                return(_value);
            }

            var baseUnitValue = AsBaseUnit();

            switch (unit)
            {
            case MassFluxUnit.GramPerHourPerSquareCentimeter: return(baseUnitValue * 3.6e2);

            case MassFluxUnit.GramPerHourPerSquareMeter: return(baseUnitValue * 3.6e6);

            case MassFluxUnit.GramPerHourPerSquareMillimeter: return(baseUnitValue * 3.6e0);

            case MassFluxUnit.GramPerSecondPerSquareCentimeter: return(baseUnitValue * 1e-1);

            case MassFluxUnit.GramPerSecondPerSquareMeter: return(baseUnitValue * 1e3);

            case MassFluxUnit.GramPerSecondPerSquareMillimeter: return(baseUnitValue * 1e-3);

            case MassFluxUnit.KilogramPerHourPerSquareCentimeter: return((baseUnitValue * 3.6e2) / 1e3d);

            case MassFluxUnit.KilogramPerHourPerSquareMeter: return((baseUnitValue * 3.6e6) / 1e3d);

            case MassFluxUnit.KilogramPerHourPerSquareMillimeter: return((baseUnitValue * 3.6e0) / 1e3d);

            case MassFluxUnit.KilogramPerSecondPerSquareCentimeter: return((baseUnitValue * 1e-1) / 1e3d);

            case MassFluxUnit.KilogramPerSecondPerSquareMeter: return((baseUnitValue * 1e3) / 1e3d);

            case MassFluxUnit.KilogramPerSecondPerSquareMillimeter: return((baseUnitValue * 1e-3) / 1e3d);

            default:
                throw new NotImplementedException($"Can not convert {Unit} to {unit}.");
            }
        }
Пример #2
0
        public string ToString(MassFluxUnit 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));
        }
 /// <summary>
 ///     Dynamically convert from value and unit enum <see cref="MassFluxUnit" /> to <see cref="MassFlux" />.
 /// </summary>
 /// <param name="value">Value to convert from.</param>
 /// <param name="fromUnit">Unit to convert from.</param>
 /// <returns>MassFlux unit value.</returns>
 public static MassFlux?From(QuantityValue?value, MassFluxUnit fromUnit)
 {
     return(value.HasValue ? new MassFlux((double)value.Value, fromUnit) : default(MassFlux?));
 }
 /// <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(MassFluxUnit unit, [CanBeNull] IFormatProvider provider)
 {
     return(ToString(unit, provider, 2));
 }
Пример #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 MassFlux(double value, MassFluxUnit unit)
 {
     _value = value;
     _unit  = unit;
 }
Пример #6
0
 public static string GetAbbreviation(MassFluxUnit unit, [CanBeNull] Culture culture)
 {
     return(UnitSystem.GetCached(culture).GetDefaultAbbreviation(unit));
 }
Пример #7
0
        /// <summary>
        ///     Converts this MassFlux to another MassFlux with the unit representation <paramref name="unit" />.
        /// </summary>
        /// <returns>A MassFlux with the specified unit.</returns>
        public MassFlux ToUnit(MassFluxUnit unit)
        {
            var convertedValue = AsBaseNumericType(unit);

            return(new MassFlux(convertedValue, unit));
        }
Пример #8
0
        public static MassFlux From(QuantityValue value, MassFluxUnit fromUnit)
#endif
        {
            return(new MassFlux((double)value, fromUnit));
        }
Пример #9
0
 MassFlux(double numericValue, MassFluxUnit unit)
 {
     _value = numericValue;
     _unit  = unit;
 }
Пример #10
0
 public static bool TryParseUnit(string str, out MassFluxUnit unit)
 {
     return(TryParseUnit(str, null, out unit));
 }
Пример #11
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(MassFluxUnit unit, [CanBeNull] string cultureName)
        {
            IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);

            return(UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider));
        }
Пример #12
0
        public static string GetAbbreviation(MassFluxUnit unit, [CanBeNull] IFormatProvider provider)
        {
            provider = provider ?? UnitSystem.DefaultCulture;

            return(UnitSystem.GetCached(provider).GetDefaultAbbreviation(unit));
        }
Пример #13
0
 public static MassFlux From(decimal value, MassFluxUnit fromUnit)
 {
     return(new MassFlux((decimal)value, fromUnit));
 }
Пример #14
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(MassFluxUnit unit, [CanBeNull] Culture culture)
 {
     return(ToString(unit, culture, 2));
 }
Пример #15
0
        public static string GetAbbreviation(
            MassFluxUnit unit,
#if WINDOWS_UWP
            [CanBeNull] string cultureName)
Пример #16
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 MassFluxUnit unit)
        {
            IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);

            return(UnitParser.Default.TryParse <MassFluxUnit>(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="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(MassFluxUnit unit, [CanBeNull] string cultureName)
 {
     return(ToString(unit, cultureName, 2));
 }
Пример #18
0
 /// <summary>
 ///     Dynamically convert from value and unit enum <see cref="MassFluxUnit" /> to <see cref="MassFlux" />.
 /// </summary>
 /// <param name="value">Value to convert from.</param>
 /// <param name="fromUnit">Unit to convert from.</param>
 /// <returns>MassFlux unit value.</returns>
 public static MassFlux From(double value, MassFluxUnit fromUnit)
 {
     return(new MassFlux(value, fromUnit));
 }
Пример #19
0
 public static MassFlux From(double value, MassFluxUnit fromUnit)
Пример #20
0
 /// <summary>
 ///     Convert to the unit representation <paramref name="unit" />.
 /// </summary>
 /// <returns>Value converted to the specified unit.</returns>
 public double As(MassFluxUnit unit) => GetValueAs(unit);
Пример #21
0
 public static string GetAbbreviation(MassFluxUnit unit)
 {
     return(GetAbbreviation(unit, null));
 }
Пример #22
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 MassFlux ToUnit(MassFluxUnit unit)
        {
            var convertedValue = GetValueAs(unit);

            return(new MassFlux(convertedValue, unit));
        }
Пример #23
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(MassFluxUnit unit)
 {
     return(ToString(unit, null, 2));
 }
Пример #24
0
 public static void HasConversion(this PropertyBuilder <MassFlux> propertyBuilder, MassFluxUnit unit) =>
 propertyBuilder.HasConversion(v => v.As(unit), v => new MassFlux(v, unit));