コード例 #1
0
 public void JerkConversions(double value1, JerkUnit units1, double value2, JerkUnit units2)
 {
     new Jerk(value1, units1) {
         Units = units2
     }.Value.ShouldBeWithinEpsilonOf(value2);
     new Jerk(value2, units2) {
         Units = units1
     }.Value.ShouldBeWithinEpsilonOf(value1);
 }
コード例 #2
0
ファイル: Jerk.g.cs プロジェクト: Pentiva/UnitsNet
        /// <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 Jerk(double value, JerkUnit unit)
        {
            if (unit == JerkUnit.Undefined)
            {
                throw new ArgumentException("The quantity can not be created with an undefined unit.", nameof(unit));
            }

            _value = Guard.EnsureValidNumber(value, nameof(value));
            _unit  = unit;
        }
コード例 #3
0
ファイル: Jerk.g.cs プロジェクト: Pentiva/UnitsNet
        /// <summary>
        ///     Convert to the unit representation <paramref name="unit" />.
        /// </summary>
        /// <returns>Value converted to the specified unit.</returns>
        public double As(JerkUnit unit)
        {
            if (Unit == unit)
            {
                return(Convert.ToDouble(Value));
            }

            var converted = AsBaseNumericType(unit);

            return(Convert.ToDouble(converted));
        }
コード例 #4
0
ファイル: Jerk.g.cs プロジェクト: Pentiva/UnitsNet
        private double AsBaseNumericType(JerkUnit unit)
        {
            if (Unit == unit)
            {
                return(_value);
            }

            var baseUnitValue = AsBaseUnit();

            switch (unit)
            {
            case JerkUnit.CentimeterPerSecondCubed: return((baseUnitValue) / 1e-2d);

            case JerkUnit.DecimeterPerSecondCubed: return((baseUnitValue) / 1e-1d);

            case JerkUnit.FootPerSecondCubed: return(baseUnitValue / 0.304800);

            case JerkUnit.InchPerSecondCubed: return(baseUnitValue / 0.0254);

            case JerkUnit.KilometerPerSecondCubed: return((baseUnitValue) / 1e3d);

            case JerkUnit.MeterPerSecondCubed: return(baseUnitValue);

            case JerkUnit.MicrometerPerSecondCubed: return((baseUnitValue) / 1e-6d);

            case JerkUnit.MillimeterPerSecondCubed: return((baseUnitValue) / 1e-3d);

            case JerkUnit.MillistandardGravitiesPerSecond: return((baseUnitValue / 9.80665) / 1e-3d);

            case JerkUnit.NanometerPerSecondCubed: return((baseUnitValue) / 1e-9d);

            case JerkUnit.StandardGravitiesPerSecond: return(baseUnitValue / 9.80665);

            default:
                throw new NotImplementedException($"Can not convert {Unit} to {unit}.");
            }
        }
コード例 #5
0
ファイル: Jerk.g.cs プロジェクト: Pentiva/UnitsNet
        /// <summary>
        ///     Converts this Jerk to another Jerk with the unit representation <paramref name="unit" />.
        /// </summary>
        /// <returns>A Jerk with the specified unit.</returns>
        public Jerk ToUnit(JerkUnit unit)
        {
            var convertedValue = AsBaseNumericType(unit);

            return(new Jerk(convertedValue, unit));
        }
コード例 #6
0
ファイル: Jerk.g.cs プロジェクト: Pentiva/UnitsNet
        /// <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 JerkUnit unit)
        {
            IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);

            return(UnitParser.Default.TryParse <JerkUnit>(str, provider, out unit));
        }
コード例 #7
0
ファイル: Jerk.g.cs プロジェクト: Pentiva/UnitsNet
 public static bool TryParseUnit(string str, out JerkUnit unit)
 {
     return(TryParseUnit(str, null, out unit));
 }
コード例 #8
0
ファイル: Jerk.g.cs プロジェクト: Pentiva/UnitsNet
 public static Jerk From(double value, JerkUnit fromUnit)
 {
     return(new Jerk((double)value, fromUnit));
 }
コード例 #9
0
 /// <summary>
 /// Initializes a new instance of <see cref="Gu.Units.Wpf.JerkConverter"/>.
 /// </summary>
 /// <param name="unit"><see cref="Gu.Units.JerkUnit"/>.</param>
 public JerkConverter(JerkUnit unit)
 {
     Unit = unit;
 }
コード例 #10
0
ファイル: Jerk.g.cs プロジェクト: Pentiva/UnitsNet
 /// <summary>
 ///     Get unit abbreviation string.
 /// </summary>
 /// <param name="unit">Unit to get abbreviation for.</param>
 /// <returns>Unit abbreviation string.</returns>
 public static string GetAbbreviation(JerkUnit unit)
 {
     return(GetAbbreviation(unit, null));
 }
コード例 #11
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 Jerk(double value, JerkUnit unit)
 {
     _value = value;
     _unit  = unit;
 }
コード例 #12
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 Jerk ToUnit(JerkUnit unit)
        {
            var convertedValue = GetValueAs(unit);

            return(new Jerk(convertedValue, unit));
        }
コード例 #13
0
 /// <summary>
 ///     Convert to the unit representation <paramref name="unit" />.
 /// </summary>
 /// <returns>Value converted to the specified unit.</returns>
 public double As(JerkUnit unit) => GetValueAs(unit);
コード例 #14
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Gu.Units.Wpf.JerkConverter"/> class.
 /// </summary>
 /// <param name="unit"><see cref="Gu.Units.JerkUnit"/>.</param>
 public JerkConverter(JerkUnit unit)
 {
     this.Unit = unit;
 }
コード例 #15
0
ファイル: Jerk.g.cs プロジェクト: Pentiva/UnitsNet
        /// <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(JerkUnit unit, [CanBeNull] string cultureName)
        {
            IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);

            return(UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider));
        }
コード例 #16
0
 private JerkJsonConverter(JerkUnit unit)
 {
     this.unit = unit;
 }
コード例 #17
0
 protected static string CreateSuffix(SymbolFormat format, JerkUnit unit)
 {
     return default(Jerk).ToString(unit, format).Trim('0');
 }