private decimal AsBaseNumericType(RotationalStiffnessPerLengthUnit unit)
        {
            if (Unit == unit)
            {
                return(_value);
            }

            var baseUnitValue = AsBaseUnit();

            switch (unit)
            {
            case RotationalStiffnessPerLengthUnit.KilonewtonMeterPerRadianPerMeter: return((baseUnitValue) / 1e3m);

            case RotationalStiffnessPerLengthUnit.KilopoundForceFootPerDegreesPerFoot: return(baseUnitValue / 254864.324570m);

            case RotationalStiffnessPerLengthUnit.MeganewtonMeterPerRadianPerMeter: return((baseUnitValue) / 1e6m);

            case RotationalStiffnessPerLengthUnit.NewtonMeterPerRadianPerMeter: return(baseUnitValue);

            case RotationalStiffnessPerLengthUnit.PoundForceFootPerDegreesPerFoot: return(baseUnitValue / 254.864324570m);

            default:
                throw new NotImplementedException($"Can not convert {Unit} to {unit}.");
            }
        }
Example #2
0
        public static string GetAbbreviation(RotationalStiffnessPerLengthUnit 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));
        }
Example #3
0
        public string ToString(RotationalStiffnessPerLengthUnit unit, [CanBeNull] string cultureName, int significantDigitsAfterRadix)
        {
            double value  = As(unit);
            string format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix);

            return(ToString(unit, cultureName, format));
        }
        /// <summary>
        ///     Convert to the unit representation <paramref name="unit" />.
        /// </summary>
        /// <returns>Value converted to the specified unit.</returns>
        public double As(RotationalStiffnessPerLengthUnit unit)
        {
            if(Unit == unit)
                return Convert.ToDouble(Value);

            var converted = AsBaseNumericType(unit);
            return Convert.ToDouble(converted);
        }
Example #5
0
        // Windows Runtime Component does not support nullable types (double?): https://msdn.microsoft.com/en-us/library/br230301.aspx
#if !WINDOWS_UWP
        /// <summary>
        ///     Dynamically convert from value and unit enum <see cref="RotationalStiffnessPerLengthUnit" /> to <see cref="RotationalStiffnessPerLength" />.
        /// </summary>
        /// <param name="value">Value to convert from.</param>
        /// <param name="fromUnit">Unit to convert from.</param>
        /// <returns>RotationalStiffnessPerLength unit value.</returns>
        public static RotationalStiffnessPerLength?From(QuantityValue?value, RotationalStiffnessPerLengthUnit fromUnit)
        {
            if (!value.HasValue)
            {
                return(null);
            }

            return(new RotationalStiffnessPerLength((double)value.Value, fromUnit));
        }
Example #6
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 RotationalStiffnessPerLength(double value, RotationalStiffnessPerLengthUnit unit)
        {
            if (unit == RotationalStiffnessPerLengthUnit.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>
        ///     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 RotationalStiffnessPerLength(decimal value, RotationalStiffnessPerLengthUnit unit)
        {
            if (unit == RotationalStiffnessPerLengthUnit.Undefined)
            {
                throw new ArgumentException("The quantity can not be created with an undefined unit.", nameof(unit));
            }

            _value = value;
            _unit  = unit;
        }
        private double AsBaseNumericType(RotationalStiffnessPerLengthUnit unit)
        {
            if (Unit == unit)
            {
                return(_value);
            }

            var baseUnitValue = AsBaseUnit();

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

            case RotationalStiffnessPerLengthUnit.DecanewtonMeterPerRadianPerMeter: return((baseUnitValue) / 1e1d);

            case RotationalStiffnessPerLengthUnit.DecinewtonMeterPerRadianPerMeter: return((baseUnitValue) / 1e-1d);

            case RotationalStiffnessPerLengthUnit.ExanewtonMeterPerRadianPerMeter: return((baseUnitValue) / 1e18d);

            case RotationalStiffnessPerLengthUnit.FemtonewtonMeterPerRadianPerMeter: return((baseUnitValue) / 1e-15d);

            case RotationalStiffnessPerLengthUnit.GiganewtonMeterPerRadianPerMeter: return((baseUnitValue) / 1e9d);

            case RotationalStiffnessPerLengthUnit.HectonewtonMeterPerRadianPerMeter: return((baseUnitValue) / 1e2d);

            case RotationalStiffnessPerLengthUnit.KilonewtonMeterPerRadianPerMeter: return((baseUnitValue) / 1e3d);

            case RotationalStiffnessPerLengthUnit.MeganewtonMeterPerRadianPerMeter: return((baseUnitValue) / 1e6d);

            case RotationalStiffnessPerLengthUnit.MicronewtonMeterPerRadianPerMeter: return((baseUnitValue) / 1e-6d);

            case RotationalStiffnessPerLengthUnit.MillinewtonMeterPerRadianPerMeter: return((baseUnitValue) / 1e-3d);

            case RotationalStiffnessPerLengthUnit.NanonewtonMeterPerRadianPerMeter: return((baseUnitValue) / 1e-9d);

            case RotationalStiffnessPerLengthUnit.NewtonMeterPerRadianPerMeter: return(baseUnitValue);

            case RotationalStiffnessPerLengthUnit.PetanewtonMeterPerRadianPerMeter: return((baseUnitValue) / 1e15d);

            case RotationalStiffnessPerLengthUnit.PiconewtonMeterPerRadianPerMeter: return((baseUnitValue) / 1e-12d);

            case RotationalStiffnessPerLengthUnit.QutranewtonMeterPerRadianPerMeter: return((baseUnitValue) / 1e27d);

            case RotationalStiffnessPerLengthUnit.TeranewtonMeterPerRadianPerMeter: return((baseUnitValue) / 1e12d);

            case RotationalStiffnessPerLengthUnit.VettanewtonMeterPerRadianPerMeter: return((baseUnitValue) / 1e30d);

            case RotationalStiffnessPerLengthUnit.YottanewtonMeterPerRadianPerMeter: return((baseUnitValue) / 1e24d);

            case RotationalStiffnessPerLengthUnit.ZettanewtonMeterPerRadianPerMeter: return((baseUnitValue) / 1e21d);

            default:
                throw new NotImplementedException($"Can not convert {Unit} to {unit}.");
            }
        }
        /// <summary>
        ///     Convert to the unit representation <paramref name="unit" />.
        /// </summary>
        /// <returns>Value converted to the specified unit.</returns>
        public decimal As(RotationalStiffnessPerLengthUnit unit)
        {
            if (Unit == unit)
            {
                return(Convert.ToDecimal(Value));
            }

            var converted = AsBaseNumericType(unit);

            return(Convert.ToDecimal(converted));
        }
// ReSharper restore VirtualMemberNeverOverriden.Global

        protected (double UnitsInBaseUnit, double Tolerence) GetConversionFactor(RotationalStiffnessPerLengthUnit unit)
        {
            return(unit switch
            {
                RotationalStiffnessPerLengthUnit.KilonewtonMeterPerRadianPerMeter => (KilonewtonMetersPerRadianPerMeterInOneNewtonMeterPerRadianPerMeter, KilonewtonMetersPerRadianPerMeterTolerance),
                RotationalStiffnessPerLengthUnit.KilopoundForceFootPerDegreesPerFoot => (KilopoundForceFeetPerDegreesPerFeetInOneNewtonMeterPerRadianPerMeter, KilopoundForceFeetPerDegreesPerFeetTolerance),
                RotationalStiffnessPerLengthUnit.MeganewtonMeterPerRadianPerMeter => (MeganewtonMetersPerRadianPerMeterInOneNewtonMeterPerRadianPerMeter, MeganewtonMetersPerRadianPerMeterTolerance),
                RotationalStiffnessPerLengthUnit.NewtonMeterPerRadianPerMeter => (NewtonMetersPerRadianPerMeterInOneNewtonMeterPerRadianPerMeter, NewtonMetersPerRadianPerMeterTolerance),
                RotationalStiffnessPerLengthUnit.PoundForceFootPerDegreesPerFoot => (PoundForceFeetPerDegreesPerFeetInOneNewtonMeterPerRadianPerMeter, PoundForceFeetPerDegreesPerFeetTolerance),
                _ => throw new NotSupportedException()
            });
        private double AsBaseNumericType(RotationalStiffnessPerLengthUnit unit)
        {
            if(Unit == unit)
                return _value;

            var baseUnitValue = AsBaseUnit();

            switch(unit)
            {
                case RotationalStiffnessPerLengthUnit.KilonewtonMeterPerRadianPerMeter: return (baseUnitValue) / 1e3d;
                case RotationalStiffnessPerLengthUnit.MeganewtonMeterPerRadianPerMeter: return (baseUnitValue) / 1e6d;
                case RotationalStiffnessPerLengthUnit.NewtonMeterPerRadianPerMeter: return baseUnitValue;
                default:
                    throw new NotImplementedException($"Can not convert {Unit} to {unit}.");
            }
        }
        /// <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 RotationalStiffnessPerLength Parse(string str, [CanBeNull] IFormatProvider provider)
        {
            if (str == null)
            {
                throw new ArgumentNullException(nameof(str));
            }

            provider = provider ?? UnitSystem.DefaultCulture;

            return(QuantityParser.Parse <RotationalStiffnessPerLength, RotationalStiffnessPerLengthUnit>(str, provider,
                                                                                                         delegate(string value, string unit, IFormatProvider formatProvider2)
            {
                double parsedValue = double.Parse(value, formatProvider2);
                RotationalStiffnessPerLengthUnit parsedUnit = ParseUnit(unit, formatProvider2);
                return From(parsedValue, parsedUnit);
            }, (x, y) => FromNewtonMetersPerRadianPerMeter(x.NewtonMetersPerRadianPerMeter + y.NewtonMetersPerRadianPerMeter)));
        }
        public string ToString(RotationalStiffnessPerLengthUnit 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));
        }
Example #14
0
        /// <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 RotationalStiffnessPerLength 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 <RotationalStiffnessPerLength, RotationalStiffnessPerLengthUnit>(str, provider,
                                                                                                         delegate(string value, string unit, IFormatProvider formatProvider2)
            {
                double parsedValue = double.Parse(value, formatProvider2);
                RotationalStiffnessPerLengthUnit parsedUnit = ParseUnit(unit, formatProvider2);
                return From(parsedValue, parsedUnit);
            }, (x, y) => FromNewtonMetersPerRadianPerMeter(x.NewtonMetersPerRadianPerMeter + y.NewtonMetersPerRadianPerMeter)));
        }
Example #15
0
        public string ToString(RotationalStiffnessPerLengthUnit 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));
        }
        public static string GetAbbreviation(RotationalStiffnessPerLengthUnit unit, [CanBeNull] IFormatProvider provider)
        {
            provider = provider ?? UnitSystem.DefaultCulture;

            return(UnitSystem.GetCached(provider).GetDefaultAbbreviation(unit));
        }
        /// <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(RotationalStiffnessPerLengthUnit unit, [CanBeNull] string cultureName)
        {
            IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);

            return(UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider));
        }
 /// <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(RotationalStiffnessPerLengthUnit unit, [CanBeNull] IFormatProvider provider)
 {
     return(ToString(unit, provider, 2));
 }
Example #19
0
 /// <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(RotationalStiffnessPerLengthUnit unit, [CanBeNull] string cultureName)
 {
     return(ToString(unit, cultureName, 2));
 }
 /// <summary>
 ///     Dynamically convert from value and unit enum <see cref="RotationalStiffnessPerLengthUnit" /> to <see cref="RotationalStiffnessPerLength" />.
 /// </summary>
 /// <param name="value">Value to convert from.</param>
 /// <param name="fromUnit">Unit to convert from.</param>
 /// <returns>RotationalStiffnessPerLength unit value.</returns>
 public static RotationalStiffnessPerLength?From(QuantityValue?value, RotationalStiffnessPerLengthUnit fromUnit)
 {
     return(value.HasValue ? new RotationalStiffnessPerLength((double)value.Value, fromUnit) : default(RotationalStiffnessPerLength?));
 }
Example #21
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(RotationalStiffnessPerLengthUnit unit)
 {
     return(ToString(unit, null, 2));
 }
        /// <summary>
        ///     Converts this RotationalStiffnessPerLength to another RotationalStiffnessPerLength with the unit representation <paramref name="unit" />.
        /// </summary>
        /// <returns>A RotationalStiffnessPerLength with the specified unit.</returns>
        public RotationalStiffnessPerLength ToUnit(RotationalStiffnessPerLengthUnit unit)
        {
            var convertedValue = AsBaseNumericType(unit);

            return(new RotationalStiffnessPerLength(convertedValue, unit));
        }
Example #23
0
 public static RotationalStiffnessPerLength From(double value, RotationalStiffnessPerLengthUnit fromUnit)
Example #24
0
 public static string GetAbbreviation(RotationalStiffnessPerLengthUnit unit)
 {
     return(GetAbbreviation(unit, null));
 }
Example #25
0
 RotationalStiffnessPerLength(double numericValue, RotationalStiffnessPerLengthUnit unit)
 {
     _value = numericValue;
     _unit  = unit;
 }
 public static RotationalStiffnessPerLength From(decimal value, RotationalStiffnessPerLengthUnit fromUnit)
 {
     return(new RotationalStiffnessPerLength((decimal)value, fromUnit));
 }
Example #27
0
        public static RotationalStiffnessPerLength From(QuantityValue value, RotationalStiffnessPerLengthUnit fromUnit)
#endif
        {
            return(new RotationalStiffnessPerLength((double)value, fromUnit));
        }
 public static bool TryParseUnit(string str, out RotationalStiffnessPerLengthUnit unit)
 {
     return(TryParseUnit(str, null, out unit));
 }
Example #29
0
        public static string GetAbbreviation(
            RotationalStiffnessPerLengthUnit unit,
#if WINDOWS_UWP
            [CanBeNull] string cultureName)
        /// <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 RotationalStiffnessPerLengthUnit unit)
        {
            IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);

            return(UnitParser.Default.TryParse <RotationalStiffnessPerLengthUnit>(str, provider, out unit));
        }