private double AsBaseNumericType(TorquePerLengthUnit unit) { if (Unit == unit) { return(_value); } var baseUnitValue = AsBaseUnit(); switch (unit) { case TorquePerLengthUnit.DecanewtonMeterPerMeter: return(baseUnitValue / 10); case TorquePerLengthUnit.KilogramForceCentimeterPerMeter: return(baseUnitValue * 10.1971619222242); case TorquePerLengthUnit.KilogramForceMeterPerMeter: return(baseUnitValue * 0.101971619222242); case TorquePerLengthUnit.KilogramForceMillimeterPerMeter: return(baseUnitValue * 101.971619222242); case TorquePerLengthUnit.KilonewtonCentimeterPerMeter: return((baseUnitValue * 100) / 1e3d); case TorquePerLengthUnit.KilonewtonMeterPerMeter: return((baseUnitValue) / 1e3d); case TorquePerLengthUnit.KilonewtonMillimeterPerMeter: return((baseUnitValue * 1000) / 1e3d); case TorquePerLengthUnit.KilopoundForceFootPerFoot: return((baseUnitValue / 4.44822161526) / 1e3d); case TorquePerLengthUnit.KilopoundForceInchPerFoot: return((baseUnitValue / 0.370685147638) / 1e3d); case TorquePerLengthUnit.MeganewtonCentimeterPerMeter: return((baseUnitValue * 100) / 1e6d); case TorquePerLengthUnit.MeganewtonMeterPerMeter: return((baseUnitValue) / 1e6d); case TorquePerLengthUnit.MeganewtonMillimeterPerMeter: return((baseUnitValue * 1000) / 1e6d); case TorquePerLengthUnit.MegapoundForceFootPerFoot: return((baseUnitValue / 4.44822161526) / 1e6d); case TorquePerLengthUnit.MegapoundForceInchPerFoot: return((baseUnitValue / 0.370685147638) / 1e6d); case TorquePerLengthUnit.NewtonCentimeterPerMeter: return(baseUnitValue * 100); case TorquePerLengthUnit.NewtonMeterPerMeter: return(baseUnitValue); case TorquePerLengthUnit.NewtonMillimeterPerMeter: return(baseUnitValue * 1000); case TorquePerLengthUnit.PoundForceFootPerFoot: return(baseUnitValue / 4.44822161526); case TorquePerLengthUnit.PoundForceInchPerFoot: return(baseUnitValue / 0.370685147638); case TorquePerLengthUnit.TonneForceCentimeterPerMeter: return(baseUnitValue * 0.0101971619222242); case TorquePerLengthUnit.TonneForceMeterPerMeter: return(baseUnitValue * 0.000101971619222242); case TorquePerLengthUnit.TonneForceMillimeterPerMeter: return(baseUnitValue * 0.101971619222242); default: throw new NotImplementedException($"Can not convert {Unit} to {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 TorquePerLength(decimal value, TorquePerLengthUnit unit) { if (unit == TorquePerLengthUnit.Undefined) { throw new ArgumentException("The quantity can not be created with an undefined unit.", nameof(unit)); } _value = value; _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 TorquePerLength(double value, TorquePerLengthUnit unit) { if (unit == TorquePerLengthUnit.Undefined) { throw new ArgumentException("The quantity can not be created with an undefined unit.", nameof(unit)); } _value = Guard.EnsureValidNumber(value, nameof(value)); _unit = unit; }
/// <summary> /// Convert to the unit representation <paramref name="unit" />. /// </summary> /// <returns>Value converted to the specified unit.</returns> public decimal As(TorquePerLengthUnit unit) { if (Unit == unit) { return(Convert.ToDecimal(Value)); } var converted = AsBaseNumericType(unit); return(Convert.ToDecimal(converted)); }
/// <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 TorquePerLength(double value, TorquePerLengthUnit unit) { _value = value; _unit = 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 TorquePerLength ToUnit(TorquePerLengthUnit unit) { var convertedValue = GetValueAs(unit); return(new TorquePerLength(convertedValue, unit)); }
/// <summary> /// Convert to the unit representation <paramref name="unit" />. /// </summary> /// <returns>Value converted to the specified unit.</returns> public double As(TorquePerLengthUnit unit) => GetValueAs(unit);
/// <summary> /// Dynamically convert from value and unit enum <see cref="TorquePerLengthUnit" /> to <see cref="TorquePerLength" />. /// </summary> /// <param name="value">Value to convert from.</param> /// <param name="fromUnit">Unit to convert from.</param> /// <returns>TorquePerLength unit value.</returns> public static TorquePerLength From(double value, TorquePerLengthUnit fromUnit) { return(new TorquePerLength(value, fromUnit)); }
/// <summary> /// Converts this TorquePerLength to another TorquePerLength with the unit representation <paramref name="unit" />. /// </summary> /// <returns>A TorquePerLength with the specified unit.</returns> public TorquePerLength ToUnit(TorquePerLengthUnit unit) { var convertedValue = AsBaseNumericType(unit); return(new TorquePerLength(convertedValue, 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 TorquePerLengthUnit unit) { IFormatProvider provider = GetFormatProviderFromCultureName(cultureName); return(UnitParser.Default.TryParse <TorquePerLengthUnit>(str, provider, out unit)); }
public static bool TryParseUnit(string str, out TorquePerLengthUnit unit) { return(TryParseUnit(str, null, out unit)); }
public static TorquePerLength From(decimal value, TorquePerLengthUnit fromUnit) { return(new TorquePerLength((decimal)value, fromUnit)); }
/// <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(TorquePerLengthUnit unit, [CanBeNull] string cultureName) { IFormatProvider provider = GetFormatProviderFromCultureName(cultureName); return(UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider)); }
/// <summary> /// Get unit abbreviation string. /// </summary> /// <param name="unit">Unit to get abbreviation for.</param> /// <returns>Unit abbreviation string.</returns> public static string GetAbbreviation(TorquePerLengthUnit unit) { return(GetAbbreviation(unit, null)); }