コード例 #1
0
        private double AsBaseNumericType(WarpingMomentOfInertiaUnit unit)
        {
            if (Unit == unit)
            {
                return(_value);
            }

            var baseUnitValue = AsBaseUnit();

            switch (unit)
            {
            case WarpingMomentOfInertiaUnit.CentimeterToTheSixth: return(baseUnitValue * 1e12);

            case WarpingMomentOfInertiaUnit.DecimeterToTheSixth: return(baseUnitValue * 1e6);

            case WarpingMomentOfInertiaUnit.FootToTheSixth: return(baseUnitValue / Math.Pow(0.3048, 6));

            case WarpingMomentOfInertiaUnit.InchToTheSixth: return(baseUnitValue / Math.Pow(2.54e-2, 6));

            case WarpingMomentOfInertiaUnit.MeterToTheSixth: return(baseUnitValue);

            case WarpingMomentOfInertiaUnit.MillimeterToTheSixth: return(baseUnitValue * 1e18);

            default:
                throw new NotImplementedException($"Can not convert {Unit} to {unit}.");
            }
        }
コード例 #2
0
        public void ToUnit(WarpingMomentOfInertiaUnit unit)
        {
            var inBaseUnits = WarpingMomentOfInertia.From(1.0, WarpingMomentOfInertia.BaseUnit);
            var converted = inBaseUnits.ToUnit(unit);

            var conversionFactor = GetConversionFactor(unit);
            AssertEx.EqualTolerance(conversionFactor.UnitsInBaseUnit, (double)converted.Value, conversionFactor.Tolerence);
            Assert.Equal(unit, converted.Unit);
        }
コード例 #3
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>
        /// <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 WarpingMomentOfInertia(decimal value, WarpingMomentOfInertiaUnit unit)
        {
            if (unit == WarpingMomentOfInertiaUnit.Undefined)
            {
                throw new ArgumentException("The quantity can not be created with an undefined unit.", nameof(unit));
            }

            _value = value;
            _unit  = unit;
        }
コード例 #4
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>
        /// <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 WarpingMomentOfInertia(double value, WarpingMomentOfInertiaUnit unit)
        {
            if (unit == WarpingMomentOfInertiaUnit.Undefined)
            {
                throw new ArgumentException("The quantity can not be created with an undefined unit.", nameof(unit));
            }

            _value = Guard.EnsureValidNumber(value, nameof(value));
            _unit  = unit;
        }
コード例 #5
0
        /// <summary>
        ///     Convert to the unit representation <paramref name="unit" />.
        /// </summary>
        /// <returns>Value converted to the specified unit.</returns>
        public double As(WarpingMomentOfInertiaUnit unit)
        {
            if (Unit == unit)
            {
                return(Convert.ToDouble(Value));
            }

            var converted = AsBaseNumericType(unit);

            return(Convert.ToDouble(converted));
        }
コード例 #6
0
// ReSharper restore VirtualMemberNeverOverriden.Global

        protected (double UnitsInBaseUnit, double Tolerence) GetConversionFactor(WarpingMomentOfInertiaUnit unit)
        {
            return(unit switch
            {
                WarpingMomentOfInertiaUnit.CentimeterToTheSixth => (CentimetersToTheSixthInOneMeterToTheSixth, CentimetersToTheSixthTolerance),
                WarpingMomentOfInertiaUnit.DecimeterToTheSixth => (DecimetersToTheSixthInOneMeterToTheSixth, DecimetersToTheSixthTolerance),
                WarpingMomentOfInertiaUnit.FootToTheSixth => (FeetToTheSixthInOneMeterToTheSixth, FeetToTheSixthTolerance),
                WarpingMomentOfInertiaUnit.InchToTheSixth => (InchesToTheSixthInOneMeterToTheSixth, InchesToTheSixthTolerance),
                WarpingMomentOfInertiaUnit.MeterToTheSixth => (MetersToTheSixthInOneMeterToTheSixth, MetersToTheSixthTolerance),
                WarpingMomentOfInertiaUnit.MillimeterToTheSixth => (MillimetersToTheSixthInOneMeterToTheSixth, MillimetersToTheSixthTolerance),
                _ => throw new NotSupportedException()
            });
コード例 #7
0
        public void ToUnit_FromNonBaseUnit_ReturnsQuantityWithGivenUnit(WarpingMomentOfInertiaUnit unit)
        {
            // See if there is a unit available that is not the base unit.
            var fromUnit = WarpingMomentOfInertia.Units.FirstOrDefault(u => u != WarpingMomentOfInertia.BaseUnit && u != WarpingMomentOfInertiaUnit.Undefined);

            // If there is only one unit for the quantity, we must use the base unit.
            if (fromUnit == WarpingMomentOfInertiaUnit.Undefined)
                fromUnit = WarpingMomentOfInertia.BaseUnit;

            var quantity = WarpingMomentOfInertia.From(3.0, fromUnit);
            var converted = quantity.ToUnit(unit);
            Assert.Equal(converted.Unit, unit);
        }
コード例 #8
0
        /// <summary>
        ///     Converts this WarpingMomentOfInertia to another WarpingMomentOfInertia with the unit representation <paramref name="unit" />.
        /// </summary>
        /// <returns>A WarpingMomentOfInertia with the specified unit.</returns>
        public WarpingMomentOfInertia ToUnit(WarpingMomentOfInertiaUnit unit)
        {
            var convertedValue = AsBaseNumericType(unit);

            return(new WarpingMomentOfInertia(convertedValue, unit));
        }
コード例 #9
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 WarpingMomentOfInertiaUnit unit)
        {
            IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);

            return(UnitParser.Default.TryParse <WarpingMomentOfInertiaUnit>(str, provider, out unit));
        }
コード例 #10
0
 public static bool TryParseUnit(string str, out WarpingMomentOfInertiaUnit unit)
 {
     return(TryParseUnit(str, null, out unit));
 }
コード例 #11
0
 public static WarpingMomentOfInertia From(double value, WarpingMomentOfInertiaUnit fromUnit)
 {
     return(new WarpingMomentOfInertia((double)value, fromUnit));
 }
コード例 #12
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(WarpingMomentOfInertiaUnit unit, [CanBeNull] string cultureName)
        {
            IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);

            return(UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider));
        }
コード例 #13
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 WarpingMomentOfInertia ToUnit(WarpingMomentOfInertiaUnit unit)
        {
            var convertedValue = GetValueAs(unit);

            return(new WarpingMomentOfInertia(convertedValue, unit));
        }
コード例 #14
0
 public void ToUnit_WithSameUnits_AreEqual(WarpingMomentOfInertiaUnit unit)
 {
     var quantity = WarpingMomentOfInertia.From(3.0, unit);
     var toUnitWithSameUnit = quantity.ToUnit(unit);
     Assert.Equal(quantity, toUnitWithSameUnit);
 }
コード例 #15
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 WarpingMomentOfInertia(double value, WarpingMomentOfInertiaUnit unit)
 {
     _value = value;
     _unit  = unit;
 }
コード例 #16
0
 /// <summary>
 ///     Get unit abbreviation string.
 /// </summary>
 /// <param name="unit">Unit to get abbreviation for.</param>
 /// <returns>Unit abbreviation string.</returns>
 public static string GetAbbreviation(WarpingMomentOfInertiaUnit unit)
 {
     return(GetAbbreviation(unit, null));
 }
コード例 #17
0
 /// <summary>
 ///     Convert to the unit representation <paramref name="unit" />.
 /// </summary>
 /// <returns>Value converted to the specified unit.</returns>
 public double As(WarpingMomentOfInertiaUnit unit) => GetValueAs(unit);