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}."); } }
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)); }
/// <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; }
public static string GetAbbreviation(MassFluxUnit unit, [CanBeNull] Culture culture) { return(UnitSystem.GetCached(culture).GetDefaultAbbreviation(unit)); }
/// <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)); }
public static MassFlux From(QuantityValue value, MassFluxUnit fromUnit) #endif { return(new MassFlux((double)value, fromUnit)); }
MassFlux(double numericValue, MassFluxUnit unit) { _value = numericValue; _unit = unit; }
public static bool TryParseUnit(string str, out MassFluxUnit 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(MassFluxUnit unit, [CanBeNull] string cultureName) { IFormatProvider provider = GetFormatProviderFromCultureName(cultureName); return(UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider)); }
public static string GetAbbreviation(MassFluxUnit unit, [CanBeNull] IFormatProvider provider) { provider = provider ?? UnitSystem.DefaultCulture; return(UnitSystem.GetCached(provider).GetDefaultAbbreviation(unit)); }
public static MassFlux From(decimal value, MassFluxUnit fromUnit) { return(new MassFlux((decimal)value, fromUnit)); }
/// <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)); }
public static string GetAbbreviation( MassFluxUnit unit, #if WINDOWS_UWP [CanBeNull] string cultureName)
/// <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)); }
/// <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)); }
public static MassFlux From(double value, MassFluxUnit fromUnit)
/// <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);
public static string GetAbbreviation(MassFluxUnit unit) { return(GetAbbreviation(unit, null)); }
/// <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)); }
/// <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)); }
public static void HasConversion(this PropertyBuilder <MassFlux> propertyBuilder, MassFluxUnit unit) => propertyBuilder.HasConversion(v => v.As(unit), v => new MassFlux(v, unit));