public string ToString(MassMomentOfInertiaUnit unit, [CanBeNull] IFormatProvider provider, int significantDigitsAfterRadix)
        {
            double value  = As(unit);
            string format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix);

            return(ToString(unit, provider, format));
        }
        public static string GetAbbreviation(MassMomentOfInertiaUnit 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));
        }
示例#3
0
        /// <summary>
        ///     Convert to the unit representation <paramref name="unit" />.
        /// </summary>
        /// <returns>Value converted to the specified unit.</returns>
        public double As(MassMomentOfInertiaUnit unit)
        {
            if (Unit == unit)
            {
                return(Convert.ToDouble(Value));
            }

            var converted = AsBaseNumericType(unit);

            return(Convert.ToDouble(converted));
        }
        /// <summary>
        ///     Parse a string with one or two quantities of the format "&lt;quantity&gt; &lt;unit&gt;".
        /// </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
        ///     "&lt;quantity&gt; &lt;unit&gt;". 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 MassMomentOfInertia Parse(string str, [CanBeNull] IFormatProvider provider)
        {
            if (str == null)
            {
                throw new ArgumentNullException(nameof(str));
            }

            provider = provider ?? UnitSystem.DefaultCulture;

            return(QuantityParser.Parse <MassMomentOfInertia, MassMomentOfInertiaUnit>(str, provider,
                                                                                       delegate(string value, string unit, IFormatProvider formatProvider2)
            {
                double parsedValue = double.Parse(value, formatProvider2);
                MassMomentOfInertiaUnit parsedUnit = ParseUnit(unit, formatProvider2);
                return From(parsedValue, parsedUnit);
            }, (x, y) => FromKilogramSquareMeters(x.KilogramSquareMeters + y.KilogramSquareMeters)));
        }
        public string ToString(MassMomentOfInertiaUnit 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));
        }
        /// <summary>
        ///     Parse a string with one or two quantities of the format "&lt;quantity&gt; &lt;unit&gt;".
        /// </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
        ///     "&lt;quantity&gt; &lt;unit&gt;". 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 MassMomentOfInertia 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 <MassMomentOfInertia, MassMomentOfInertiaUnit>(str, provider,
                                                                                       delegate(string value, string unit, IFormatProvider formatProvider2)
            {
                double parsedValue = double.Parse(value, formatProvider2);
                MassMomentOfInertiaUnit parsedUnit = ParseUnit(unit, formatProvider2);
                return From(parsedValue, parsedUnit);
            }, (x, y) => FromKilogramSquareMeters(x.KilogramSquareMeters + y.KilogramSquareMeters)));
        }
        public string ToString(MassMomentOfInertiaUnit 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));
        }
示例#8
0
 /// <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(MassMomentOfInertiaUnit unit)
 {
     return(ToString(unit, null, 2));
 }
 /// <summary>
 ///     Dynamically convert from value and unit enum <see cref="MassMomentOfInertiaUnit" /> to <see cref="MassMomentOfInertia" />.
 /// </summary>
 /// <param name="value">Value to convert from.</param>
 /// <param name="fromUnit">Unit to convert from.</param>
 /// <returns>MassMomentOfInertia unit value.</returns>
 public static MassMomentOfInertia From(double value, MassMomentOfInertiaUnit fromUnit)
 {
     return(new MassMomentOfInertia(value, fromUnit));
 }
示例#10
0
 public static string GetAbbreviation(MassMomentOfInertiaUnit unit)
 {
     return(GetAbbreviation(unit, null));
 }
示例#11
0
 public static MassMomentOfInertia From(double value, MassMomentOfInertiaUnit fromUnit)
示例#12
0
        private double AsBaseNumericType(MassMomentOfInertiaUnit unit)
        {
            if (Unit == unit)
            {
                return(_value);
            }

            var baseUnitValue = AsBaseUnit();

            switch (unit)
            {
            case MassMomentOfInertiaUnit.GramSquareCentimeter: return(baseUnitValue * 1e7);

            case MassMomentOfInertiaUnit.GramSquareDecimeter: return(baseUnitValue * 1e5);

            case MassMomentOfInertiaUnit.GramSquareMeter: return(baseUnitValue * 1e3);

            case MassMomentOfInertiaUnit.GramSquareMillimeter: return(baseUnitValue * 1e9);

            case MassMomentOfInertiaUnit.KilogramSquareCentimeter: return((baseUnitValue * 1e7) / 1e3d);

            case MassMomentOfInertiaUnit.KilogramSquareDecimeter: return((baseUnitValue * 1e5) / 1e3d);

            case MassMomentOfInertiaUnit.KilogramSquareMeter: return((baseUnitValue * 1e3) / 1e3d);

            case MassMomentOfInertiaUnit.KilogramSquareMillimeter: return((baseUnitValue * 1e9) / 1e3d);

            case MassMomentOfInertiaUnit.KilotonneSquareCentimeter: return((baseUnitValue * 1e1) / 1e3d);

            case MassMomentOfInertiaUnit.KilotonneSquareDecimeter: return((baseUnitValue * 1e-1) / 1e3d);

            case MassMomentOfInertiaUnit.KilotonneSquareMeter: return((baseUnitValue * 1e-3) / 1e3d);

            case MassMomentOfInertiaUnit.KilotonneSquareMilimeter: return((baseUnitValue * 1e3) / 1e3d);

            case MassMomentOfInertiaUnit.MegatonneSquareCentimeter: return((baseUnitValue * 1e1) / 1e6d);

            case MassMomentOfInertiaUnit.MegatonneSquareDecimeter: return((baseUnitValue * 1e-1) / 1e6d);

            case MassMomentOfInertiaUnit.MegatonneSquareMeter: return((baseUnitValue * 1e-3) / 1e6d);

            case MassMomentOfInertiaUnit.MegatonneSquareMilimeter: return((baseUnitValue * 1e3) / 1e6d);

            case MassMomentOfInertiaUnit.MilligramSquareCentimeter: return((baseUnitValue * 1e7) / 1e-3d);

            case MassMomentOfInertiaUnit.MilligramSquareDecimeter: return((baseUnitValue * 1e5) / 1e-3d);

            case MassMomentOfInertiaUnit.MilligramSquareMeter: return((baseUnitValue * 1e3) / 1e-3d);

            case MassMomentOfInertiaUnit.MilligramSquareMillimeter: return((baseUnitValue * 1e9) / 1e-3d);

            case MassMomentOfInertiaUnit.PoundSquareFoot: return(baseUnitValue / 4.21401101e-2);

            case MassMomentOfInertiaUnit.PoundSquareInch: return(baseUnitValue / 2.9263965e-4);

            case MassMomentOfInertiaUnit.TonneSquareCentimeter: return(baseUnitValue * 1e1);

            case MassMomentOfInertiaUnit.TonneSquareDecimeter: return(baseUnitValue * 1e-1);

            case MassMomentOfInertiaUnit.TonneSquareMeter: return(baseUnitValue * 1e-3);

            case MassMomentOfInertiaUnit.TonneSquareMilimeter: return(baseUnitValue * 1e3);

            default:
                throw new NotImplementedException($"Can not convert {Unit} to {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(MassMomentOfInertiaUnit unit, [CanBeNull] string cultureName)
 {
     return(ToString(unit, cultureName, 2));
 }
示例#14
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 MassMomentOfInertia(double value, MassMomentOfInertiaUnit unit)
 {
     _value = value;
     _unit  = unit;
 }
示例#15
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 MassMomentOfInertia ToUnit(MassMomentOfInertiaUnit unit)
        {
            var convertedValue = GetValueAs(unit);

            return(new MassMomentOfInertia(convertedValue, unit));
        }
示例#16
0
 /// <summary>
 ///     Convert to the unit representation <paramref name="unit" />.
 /// </summary>
 /// <returns>Value converted to the specified unit.</returns>
 public double As(MassMomentOfInertiaUnit unit) => GetValueAs(unit);
示例#17
0
        /// <summary>
        ///     Converts this MassMomentOfInertia to another MassMomentOfInertia with the unit representation <paramref name="unit" />.
        /// </summary>
        /// <returns>A MassMomentOfInertia with the specified unit.</returns>
        public MassMomentOfInertia ToUnit(MassMomentOfInertiaUnit unit)
        {
            var convertedValue = AsBaseNumericType(unit);

            return(new MassMomentOfInertia(convertedValue, unit));
        }
 public static MassMomentOfInertia?From(QuantityValue?value, MassMomentOfInertiaUnit fromUnit)
 {
     return(value.HasValue ? new MassMomentOfInertia((double)value.Value, fromUnit) : default(MassMomentOfInertia?));
 }
示例#19
0
 MassMomentOfInertia(double numericValue, MassMomentOfInertiaUnit unit)
 {
     _value = numericValue;
     _unit  = unit;
 }
        public static string GetAbbreviation(MassMomentOfInertiaUnit unit, [CanBeNull] IFormatProvider provider)
        {
            provider = provider ?? UnitSystem.DefaultCulture;

            return(UnitSystem.GetCached(provider).GetDefaultAbbreviation(unit));
        }
示例#21
0
        public static MassMomentOfInertia From(QuantityValue value, MassMomentOfInertiaUnit fromUnit)
#endif
        {
            return(new MassMomentOfInertia((double)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="provider">Format to use for localization and number formatting. Defaults to <see cref="UnitSystem.DefaultCulture" />.</param>
 /// <returns>String representation.</returns>
 public string ToString(MassMomentOfInertiaUnit unit, [CanBeNull] IFormatProvider provider)
 {
     return(ToString(unit, provider, 2));
 }
示例#23
0
        public static string GetAbbreviation(
            MassMomentOfInertiaUnit unit,
#if WINDOWS_UWP
            [CanBeNull] string cultureName)
示例#24
0
 public static void HasConversion(this PropertyBuilder <MassMomentOfInertia> propertyBuilder, MassMomentOfInertiaUnit unit) =>
 propertyBuilder.HasConversion(v => v.As(unit), v => new MassMomentOfInertia(v, unit));