public string ToString(HeatFluxUnit unit, [CanBeNull] IFormatProvider provider, int significantDigitsAfterRadix) { double value = As(unit); string format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix); return(ToString(unit, provider, format)); }
public string ToString(HeatFluxUnit unit, [CanBeNull] string cultureName, int significantDigitsAfterRadix) { double value = As(unit); string format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix); return(ToString(unit, cultureName, format)); }
public static string GetAbbreviation(HeatFluxUnit 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); }
/// <summary> /// Creates the quantity with the given numeric value and unit. /// </summary> /// <param name="numericValue">The numeric value to contruct this quantity with.</param> /// <param name="unit">The unit representation to contruct 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 HeatFlux(double numericValue, HeatFluxUnit unit) { if (unit == HeatFluxUnit.Undefined) { throw new ArgumentException("The quantity can not be created with an undefined unit.", nameof(unit)); } _value = Guard.EnsureValidNumber(numericValue, nameof(numericValue)); _unit = unit; }
/// <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 HeatFlux(double value, HeatFluxUnit unit) { if (unit == HeatFluxUnit.Undefined) { throw new ArgumentException("The quantity can not be created with an undefined unit.", nameof(unit)); } _value = value; _unit = unit; }
/// <summary> /// Convert to the unit representation <paramref name="unit" />. /// </summary> /// <returns>Value converted to the specified unit.</returns> public decimal As(HeatFluxUnit unit) { if (Unit == unit) { return(Convert.ToDecimal(Value)); } var converted = AsBaseNumericType(unit); return(Convert.ToDecimal(converted)); }
/// <summary> /// Convert to the unit representation <paramref name="unit" />. /// </summary> /// <returns>Value converted to the specified unit.</returns> public double As(HeatFluxUnit unit) { if (Unit == unit) { return(Convert.ToDouble(Value)); } var converted = AsBaseNumericType(unit); return(Convert.ToDouble(converted)); }
public string ToString(HeatFluxUnit 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); }
private double AsBaseNumericType(HeatFluxUnit unit) { if (Unit == unit) { return(_value); } var baseUnitValue = AsBaseUnit(); switch (unit) { case HeatFluxUnit.BtuPerHourSquareFoot: return(baseUnitValue / 3.15459075); case HeatFluxUnit.BtuPerMinuteSquareFoot: return(baseUnitValue / 1.89275445e2); case HeatFluxUnit.BtuPerSecondSquareFoot: return(baseUnitValue / 1.13565267e4); case HeatFluxUnit.BtuPerSecondSquareInch: return(baseUnitValue / 1.63533984e6); case HeatFluxUnit.CaloriePerSecondSquareCentimeter: return(baseUnitValue / 4.1868e4); case HeatFluxUnit.CentiwattPerSquareMeter: return((baseUnitValue) / 1e-2d); case HeatFluxUnit.DeciwattPerSquareMeter: return((baseUnitValue) / 1e-1d); case HeatFluxUnit.KilocaloriePerHourSquareMeter: return(baseUnitValue / 1.163); case HeatFluxUnit.KilocaloriePerSecondSquareCentimeter: return((baseUnitValue / 4.1868e4) / 1e3d); case HeatFluxUnit.KilowattPerSquareMeter: return((baseUnitValue) / 1e3d); case HeatFluxUnit.MicrowattPerSquareMeter: return((baseUnitValue) / 1e-6d); case HeatFluxUnit.MilliwattPerSquareMeter: return((baseUnitValue) / 1e-3d); case HeatFluxUnit.NanowattPerSquareMeter: return((baseUnitValue) / 1e-9d); case HeatFluxUnit.PoundForcePerFootSecond: return(baseUnitValue / 1.459390293720636e1); case HeatFluxUnit.PoundPerSecondCubed: return(baseUnitValue / 4.5359237e-1); case HeatFluxUnit.WattPerSquareFoot: return(baseUnitValue / 1.07639e1); case HeatFluxUnit.WattPerSquareInch: return(baseUnitValue / 1.5500031e3); case HeatFluxUnit.WattPerSquareMeter: return(baseUnitValue); default: throw new NotImplementedException($"Can not convert {Unit} to {unit}."); } }
/// <summary> /// Parse a string with one or two quantities of the format "<quantity> <unit>". /// </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 /// "<quantity> <unit>". 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 HeatFlux 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<HeatFlux, HeatFluxUnit>(str, provider, delegate(string value, string unit, IFormatProvider formatProvider2) { double parsedValue = double.Parse(value, formatProvider2); HeatFluxUnit parsedUnit = ParseUnit(unit, formatProvider2); return From(parsedValue, parsedUnit); }, (x, y) => FromWattsPerSquareMeter(x.WattsPerSquareMeter + y.WattsPerSquareMeter)); }
/// <summary> /// Parse a string with one or two quantities of the format "<quantity> <unit>". /// </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 /// "<quantity> <unit>". 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 HeatFlux Parse(string str, [CanBeNull] IFormatProvider provider) { if (str == null) { throw new ArgumentNullException(nameof(str)); } provider = provider ?? UnitSystem.DefaultCulture; return(QuantityParser.Parse <HeatFlux, HeatFluxUnit>(str, provider, delegate(string value, string unit, IFormatProvider formatProvider2) { double parsedValue = double.Parse(value, formatProvider2); HeatFluxUnit parsedUnit = ParseUnit(unit, formatProvider2); return From(parsedValue, parsedUnit); }, (x, y) => FromWattsPerSquareMeter(x.WattsPerSquareMeter + y.WattsPerSquareMeter))); }
public string ToString(HeatFluxUnit 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)); }
// ReSharper restore VirtualMemberNeverOverriden.Global protected (double UnitsInBaseUnit, double Tolerence) GetConversionFactor(HeatFluxUnit unit) { return(unit switch { HeatFluxUnit.BtuPerHourSquareFoot => (BtusPerHourSquareFootInOneWattPerSquareMeter, BtusPerHourSquareFootTolerance), HeatFluxUnit.BtuPerMinuteSquareFoot => (BtusPerMinuteSquareFootInOneWattPerSquareMeter, BtusPerMinuteSquareFootTolerance), HeatFluxUnit.BtuPerSecondSquareFoot => (BtusPerSecondSquareFootInOneWattPerSquareMeter, BtusPerSecondSquareFootTolerance), HeatFluxUnit.BtuPerSecondSquareInch => (BtusPerSecondSquareInchInOneWattPerSquareMeter, BtusPerSecondSquareInchTolerance), HeatFluxUnit.CaloriePerSecondSquareCentimeter => (CaloriesPerSecondSquareCentimeterInOneWattPerSquareMeter, CaloriesPerSecondSquareCentimeterTolerance), HeatFluxUnit.CentiwattPerSquareMeter => (CentiwattsPerSquareMeterInOneWattPerSquareMeter, CentiwattsPerSquareMeterTolerance), HeatFluxUnit.DeciwattPerSquareMeter => (DeciwattsPerSquareMeterInOneWattPerSquareMeter, DeciwattsPerSquareMeterTolerance), HeatFluxUnit.KilocaloriePerHourSquareMeter => (KilocaloriesPerHourSquareMeterInOneWattPerSquareMeter, KilocaloriesPerHourSquareMeterTolerance), HeatFluxUnit.KilocaloriePerSecondSquareCentimeter => (KilocaloriesPerSecondSquareCentimeterInOneWattPerSquareMeter, KilocaloriesPerSecondSquareCentimeterTolerance), HeatFluxUnit.KilowattPerSquareMeter => (KilowattsPerSquareMeterInOneWattPerSquareMeter, KilowattsPerSquareMeterTolerance), HeatFluxUnit.MicrowattPerSquareMeter => (MicrowattsPerSquareMeterInOneWattPerSquareMeter, MicrowattsPerSquareMeterTolerance), HeatFluxUnit.MilliwattPerSquareMeter => (MilliwattsPerSquareMeterInOneWattPerSquareMeter, MilliwattsPerSquareMeterTolerance), HeatFluxUnit.NanowattPerSquareMeter => (NanowattsPerSquareMeterInOneWattPerSquareMeter, NanowattsPerSquareMeterTolerance), HeatFluxUnit.PoundForcePerFootSecond => (PoundsForcePerFootSecondInOneWattPerSquareMeter, PoundsForcePerFootSecondTolerance), HeatFluxUnit.PoundPerSecondCubed => (PoundsPerSecondCubedInOneWattPerSquareMeter, PoundsPerSecondCubedTolerance), HeatFluxUnit.WattPerSquareFoot => (WattsPerSquareFootInOneWattPerSquareMeter, WattsPerSquareFootTolerance), HeatFluxUnit.WattPerSquareInch => (WattsPerSquareInchInOneWattPerSquareMeter, WattsPerSquareInchTolerance), HeatFluxUnit.WattPerSquareMeter => (WattsPerSquareMeterInOneWattPerSquareMeter, WattsPerSquareMeterTolerance), _ => throw new NotSupportedException() });
public static string GetAbbreviation(HeatFluxUnit unit) { return(GetAbbreviation(unit, null)); }
public static HeatFlux From(QuantityValue value, HeatFluxUnit fromUnit) #endif { return(new HeatFlux((double)value, fromUnit)); }
public static HeatFlux From(double value, HeatFluxUnit fromUnit)
/// <summary> /// Converts this Duration to another Duration with the unit representation <paramref name="unit" />. /// </summary> /// <returns>A Duration with the specified unit.</returns> public HeatFlux ToUnit(HeatFluxUnit unit) { var convertedValue = GetValueAs(unit); return(new HeatFlux(convertedValue, unit)); }
/// <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 HeatFlux(double value, HeatFluxUnit unit) { _value = value; _unit = 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(HeatFluxUnit unit, [CanBeNull] string cultureName) { return ToString(unit, cultureName, 2); }
/// <summary> /// Dynamically convert from value and unit enum <see cref="HeatFluxUnit" /> to <see cref="HeatFlux" />. /// </summary> /// <param name="value">Value to convert from.</param> /// <param name="fromUnit">Unit to convert from.</param> /// <returns>HeatFlux unit value.</returns> public static HeatFlux?From(QuantityValue?value, HeatFluxUnit fromUnit) { return(value.HasValue ? new HeatFlux((double)value.Value, fromUnit) : default(HeatFlux?)); }
/// <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(HeatFluxUnit unit, [CanBeNull] IFormatProvider provider) { return(ToString(unit, provider, 2)); }
/// <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(HeatFluxUnit unit) { return(ToString(unit, null, 2)); }
/// <summary> /// Convert to the unit representation <paramref name="unit" />. /// </summary> /// <returns>Value converted to the specified unit.</returns> public double As(HeatFluxUnit unit) => GetValueAs(unit);
public static string GetAbbreviation( HeatFluxUnit unit, #if WINDOWS_UWP [CanBeNull] string cultureName)
/// <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(HeatFluxUnit unit, [CanBeNull] string cultureName) { IFormatProvider provider = GetFormatProviderFromCultureName(cultureName); return(UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider)); }
/// <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 HeatFluxUnit unit) { IFormatProvider provider = GetFormatProviderFromCultureName(cultureName); return(UnitParser.Default.TryParse <HeatFluxUnit>(str, provider, out unit)); }
public static bool TryParseUnit(string str, out HeatFluxUnit unit) { return(TryParseUnit(str, null, out unit)); }
public static HeatFlux From(double value, HeatFluxUnit fromUnit) { return(new HeatFlux((double)value, fromUnit)); }
HeatFlux(double numericValue, HeatFluxUnit unit) { _value = numericValue; _unit = unit; }
/// <summary> /// Converts this HeatFlux to another HeatFlux with the unit representation <paramref name="unit" />. /// </summary> /// <returns>A HeatFlux with the specified unit.</returns> public HeatFlux ToUnit(HeatFluxUnit unit) { var convertedValue = AsBaseNumericType(unit); return(new HeatFlux(convertedValue, unit)); }