예제 #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));