コード例 #1
0
        public string ToString(ForcePerLengthUnit unit, [CanBeNull] Culture culture, int significantDigitsAfterRadix)
        {
            double value  = As(unit);
            string format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix);

            return(ToString(unit, culture, format));
        }
コード例 #2
0
        private double AsBaseNumericType(ForcePerLengthUnit unit)
        {
            if (Unit == unit)
            {
                return(_value);
            }

            var baseUnitValue = AsBaseUnit();

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

            case ForcePerLengthUnit.DecinewtonPerMeter: return((baseUnitValue) / 1e-1d);

            case ForcePerLengthUnit.KilogramForcePerMeter: return(baseUnitValue / 9.80665002864);

            case ForcePerLengthUnit.KilonewtonPerMeter: return((baseUnitValue) / 1e3d);

            case ForcePerLengthUnit.MeganewtonPerMeter: return((baseUnitValue) / 1e6d);

            case ForcePerLengthUnit.MicronewtonPerMeter: return((baseUnitValue) / 1e-6d);

            case ForcePerLengthUnit.MillinewtonPerMeter: return((baseUnitValue) / 1e-3d);

            case ForcePerLengthUnit.NanonewtonPerMeter: return((baseUnitValue) / 1e-9d);

            case ForcePerLengthUnit.NewtonPerMeter: return(baseUnitValue);

            default:
                throw new NotImplementedException($"Can not convert {Unit} to {unit}.");
            }
        }
コード例 #3
0
        public static string GetAbbreviation(ForcePerLengthUnit 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));
        }
コード例 #4
0
        /// <summary>
        ///     Dynamically convert from value and unit enum <see cref="ForcePerLengthUnit" /> to <see cref="ForcePerLength" />.
        /// </summary>
        /// <param name="val">Value to convert from.</param>
        /// <param name="fromUnit">Unit to convert from.</param>
        /// <returns>ForcePerLength unit value.</returns>
        public static ForcePerLength From(double val, ForcePerLengthUnit fromUnit)
        {
            switch (fromUnit)
            {
            case ForcePerLengthUnit.CentinewtonPerMeter:
                return(FromCentinewtonsPerMeter(val));

            case ForcePerLengthUnit.DecinewtonPerMeter:
                return(FromDecinewtonsPerMeter(val));

            case ForcePerLengthUnit.KilogramForcePerMeter:
                return(FromKilogramsForcePerMeter(val));

            case ForcePerLengthUnit.KilonewtonPerMeter:
                return(FromKilonewtonsPerMeter(val));

            case ForcePerLengthUnit.MicronewtonPerMeter:
                return(FromMicronewtonsPerMeter(val));

            case ForcePerLengthUnit.MillinewtonPerMeter:
                return(FromMillinewtonsPerMeter(val));

            case ForcePerLengthUnit.NanonewtonPerMeter:
                return(FromNanonewtonsPerMeter(val));

            case ForcePerLengthUnit.NewtonPerMeter:
                return(FromNewtonsPerMeter(val));

            default:
                throw new NotImplementedException("fromUnit: " + fromUnit);
            }
        }
コード例 #5
0
        /// <summary>
        ///     Convert to the unit representation <paramref name="unit" />.
        /// </summary>
        /// <returns>Value in new unit if successful, exception otherwise.</returns>
        /// <exception cref="NotImplementedException">If conversion was not successful.</exception>
        public double As(ForcePerLengthUnit unit)
        {
            switch (unit)
            {
            case ForcePerLengthUnit.CentinewtonPerMeter:
                return(CentinewtonsPerMeter);

            case ForcePerLengthUnit.DecinewtonPerMeter:
                return(DecinewtonsPerMeter);

            case ForcePerLengthUnit.KilogramForcePerMeter:
                return(KilogramsForcePerMeter);

            case ForcePerLengthUnit.KilonewtonPerMeter:
                return(KilonewtonsPerMeter);

            case ForcePerLengthUnit.MicronewtonPerMeter:
                return(MicronewtonsPerMeter);

            case ForcePerLengthUnit.MillinewtonPerMeter:
                return(MillinewtonsPerMeter);

            case ForcePerLengthUnit.NanonewtonPerMeter:
                return(NanonewtonsPerMeter);

            case ForcePerLengthUnit.NewtonPerMeter:
                return(NewtonsPerMeter);

            default:
                throw new NotImplementedException("unit: " + unit);
            }
        }
コード例 #6
0
ファイル: ForcePerLength.g.cs プロジェクト: rmsryu/UnitsNet
        // 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="ForcePerLengthUnit" /> to <see cref="ForcePerLength" />.
        /// </summary>
        /// <param name="value">Value to convert from.</param>
        /// <param name="fromUnit">Unit to convert from.</param>
        /// <returns>ForcePerLength unit value.</returns>
        public static ForcePerLength?From(QuantityValue?value, ForcePerLengthUnit fromUnit)
        {
            if (!value.HasValue)
            {
                return(null);
            }

            return(new ForcePerLength((double)value.Value, fromUnit));
        }
コード例 #7
0
        private double AsBaseNumericType(ForcePerLengthUnit unit)
        {
            if (Unit == unit)
            {
                return(_value);
            }

            var baseUnitValue = AsBaseUnit();

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

            case ForcePerLengthUnit.DecanewtonPerMeter: return((baseUnitValue) / 1e1d);

            case ForcePerLengthUnit.DecinewtonPerMeter: return((baseUnitValue) / 1e-1d);

            case ForcePerLengthUnit.ExanewtonPerMeter: return((baseUnitValue) / 1e18d);

            case ForcePerLengthUnit.FemtonewtonPerMeter: return((baseUnitValue) / 1e-15d);

            case ForcePerLengthUnit.GiganewtonPerMeter: return((baseUnitValue) / 1e9d);

            case ForcePerLengthUnit.HectonewtonPerMeter: return((baseUnitValue) / 1e2d);

            case ForcePerLengthUnit.KilogramForcePerMeter: return(baseUnitValue / 9.80665002864);

            case ForcePerLengthUnit.KilonewtonPerMeter: return((baseUnitValue) / 1e3d);

            case ForcePerLengthUnit.MeganewtonPerMeter: return((baseUnitValue) / 1e6d);

            case ForcePerLengthUnit.MicronewtonPerMeter: return((baseUnitValue) / 1e-6d);

            case ForcePerLengthUnit.MillinewtonPerMeter: return((baseUnitValue) / 1e-3d);

            case ForcePerLengthUnit.NanonewtonPerMeter: return((baseUnitValue) / 1e-9d);

            case ForcePerLengthUnit.NewtonPerMeter: return(baseUnitValue);

            case ForcePerLengthUnit.PetanewtonPerMeter: return((baseUnitValue) / 1e15d);

            case ForcePerLengthUnit.PiconewtonPerMeter: return((baseUnitValue) / 1e-12d);

            case ForcePerLengthUnit.QutranewtonPerMeter: return((baseUnitValue) / 1e27d);

            case ForcePerLengthUnit.TeranewtonPerMeter: return((baseUnitValue) / 1e12d);

            case ForcePerLengthUnit.VettanewtonPerMeter: return((baseUnitValue) / 1e30d);

            case ForcePerLengthUnit.YottanewtonPerMeter: return((baseUnitValue) / 1e24d);

            case ForcePerLengthUnit.ZettanewtonPerMeter: return((baseUnitValue) / 1e21d);

            default:
                throw new NotImplementedException($"Can not convert {Unit} to {unit}.");
            }
        }
コード例 #8
0
        /// <summary>
        ///     Creates the quantity with the given numeric value and unit.
        /// </summary>
        /// <param name="numericValue">The numeric value  to contruct this quantity with.</param>
        /// <param name="unit">The unit representation to contruct 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 ForcePerLength(double numericValue, ForcePerLengthUnit unit)
        {
            if (unit == ForcePerLengthUnit.Undefined)
            {
                throw new ArgumentException("The quantity can not be created with an undefined unit.", nameof(unit));
            }

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

            var converted = AsBaseNumericType(unit);

            return(Convert.ToDouble(converted));
        }
コード例 #10
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="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 ForcePerLength Parse(string str, [CanBeNull] IFormatProvider provider)
        {
            if (str == null)
            {
                throw new ArgumentNullException(nameof(str));
            }

            provider = provider ?? UnitSystem.DefaultCulture;

            return(QuantityParser.Parse <ForcePerLength, ForcePerLengthUnit>(str, provider,
                                                                             delegate(string value, string unit, IFormatProvider formatProvider2)
            {
                double parsedValue = double.Parse(value, formatProvider2);
                ForcePerLengthUnit parsedUnit = ParseUnit(unit, formatProvider2);
                return From(parsedValue, parsedUnit);
            }, (x, y) => FromNewtonsPerMeter(x.NewtonsPerMeter + y.NewtonsPerMeter)));
        }
        /// <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 ForcePerLength 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 <ForcePerLength, ForcePerLengthUnit>(str, provider,
                                                                             delegate(string value, string unit, IFormatProvider formatProvider2)
            {
                double parsedValue = double.Parse(value, formatProvider2);
                ForcePerLengthUnit parsedUnit = ParseUnit(unit, formatProvider2);
                return From(parsedValue, parsedUnit);
            }, (x, y) => FromNewtonsPerMeter(x.NewtonsPerMeter + y.NewtonsPerMeter)));
        }
コード例 #12
0
        public string ToString(ForcePerLengthUnit 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));
        }
コード例 #13
0
        private double AsBaseNumericType(ForcePerLengthUnit unit)
        {
            if (Unit == unit)
            {
                return(_value);
            }

            var baseUnitValue = AsBaseUnit();

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

            case ForcePerLengthUnit.DecinewtonPerMeter: return((baseUnitValue) / 1e-1d);

            case ForcePerLengthUnit.KilogramForcePerMeter: return(baseUnitValue / 9.80665002864);

            case ForcePerLengthUnit.KilonewtonPerMeter: return((baseUnitValue) / 1e3d);

            case ForcePerLengthUnit.KilopoundForcePerFoot: return(baseUnitValue / 14593.90292);

            case ForcePerLengthUnit.MeganewtonPerMeter: return((baseUnitValue) / 1e6d);

            case ForcePerLengthUnit.MicronewtonPerMeter: return((baseUnitValue) / 1e-6d);

            case ForcePerLengthUnit.MillinewtonPerMeter: return((baseUnitValue) / 1e-3d);

            case ForcePerLengthUnit.NanonewtonPerMeter: return((baseUnitValue) / 1e-9d);

            case ForcePerLengthUnit.NewtonPerMeter: return(baseUnitValue);

            case ForcePerLengthUnit.NewtonPerMillimeter: return(baseUnitValue / 1e3);

            case ForcePerLengthUnit.PoundForcePerFoot: return(baseUnitValue / 14.59390292);

            case ForcePerLengthUnit.PoundForcePerInch: return(baseUnitValue / 1.75126835e2);

            case ForcePerLengthUnit.PoundForcePerYard: return(baseUnitValue / 4.864634307);

            default:
                throw new NotImplementedException($"Can not convert {Unit} to {unit}.");
            }
        }
        public string ToString(ForcePerLengthUnit 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));
        }
コード例 #15
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="culture">Format to use when parsing number and unit. If it is null, it defaults to <see cref="NumberFormatInfo.CurrentInfo"/> for parsing the number and <see cref="CultureInfo.CurrentUICulture"/> for parsing the unit abbreviation by culture/language.</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 ForcePerLength Parse(string str, [CanBeNull] Culture culture)
        {
            if (str == null)
            {
                throw new ArgumentNullException("str");
            }

#if WINDOWS_UWP
            IFormatProvider formatProvider = culture == null ? null : new CultureInfo(culture);
#else
            IFormatProvider formatProvider = culture;
#endif
            return(UnitParser.ParseUnit <ForcePerLength>(str, formatProvider,
                                                         delegate(string value, string unit, IFormatProvider formatProvider2)
            {
                double parsedValue = double.Parse(value, formatProvider2);
                ForcePerLengthUnit parsedUnit = ParseUnit(unit, formatProvider2);
                return From(parsedValue, parsedUnit);
            }, (x, y) => FromNewtonsPerMeter(x.NewtonsPerMeter + y.NewtonsPerMeter)));
        }
コード例 #16
0
        public string ToString(ForcePerLengthUnit unit, [CanBeNull] Culture culture, [NotNull] string format,
                               [NotNull] params object[] args)
        {
            if (format == null)
            {
                throw new ArgumentNullException(nameof(format));
            }
            if (args == null)
            {
                throw new ArgumentNullException(nameof(args));
            }

#if WINDOWS_UWP
            IFormatProvider formatProvider = culture == null ? null : new CultureInfo(culture);
#else
            IFormatProvider formatProvider = culture;
#endif
            double   value      = As(unit);
            object[] formatArgs = UnitFormatter.GetFormatArgs(unit, value, formatProvider, args);
            return(string.Format(formatProvider, format, formatArgs));
        }
コード例 #17
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="culture">Format to use when parsing number and unit. If it is null, it defaults to <see cref="NumberFormatInfo.CurrentInfo"/> for parsing the number and <see cref="CultureInfo.CurrentUICulture"/> for parsing the unit abbreviation by culture/language.</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 ForcePerLength Parse(string str, [CanBeNull] Culture culture)
        {
            if (str == null)
            {
                throw new ArgumentNullException("str");
            }

            // Windows Runtime Component does not support CultureInfo type, so use culture name string for public methods instead: https://msdn.microsoft.com/en-us/library/br230301.aspx
#if WINDOWS_UWP
            IFormatProvider formatProvider = culture == null ? null : new CultureInfo(culture);
#else
            IFormatProvider formatProvider = culture;
#endif
            return(QuantityParser.Parse <ForcePerLength, ForcePerLengthUnit>(str, formatProvider,
                                                                             delegate(string value, string unit, IFormatProvider formatProvider2)
            {
                double parsedValue = double.Parse(value, formatProvider2);
                ForcePerLengthUnit parsedUnit = ParseUnit(unit, formatProvider2);
                return From(parsedValue, parsedUnit);
            }, (x, y) => FromNewtonsPerMeter(x.NewtonsPerMeter + y.NewtonsPerMeter)));
        }
コード例 #18
0
        public string ToString(ForcePerLengthUnit unit, [CanBeNull] Culture culture, [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 type, so use culture name string for public methods instead: https://msdn.microsoft.com/en-us/library/br230301.aspx
#if WINDOWS_UWP
            IFormatProvider formatProvider = culture == null ? null : new CultureInfo(culture);
#else
            IFormatProvider formatProvider = culture;
#endif
            double   value      = As(unit);
            object[] formatArgs = UnitFormatter.GetFormatArgs(unit, value, formatProvider, args);
            return(string.Format(formatProvider, format, formatArgs));
        }
コード例 #19
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="ForcePerLengthUnit" /> to <see cref="ForcePerLength" />.
        /// </summary>
        /// <param name="value">Value to convert from.</param>
        /// <param name="fromUnit">Unit to convert from.</param>
        /// <returns>ForcePerLength unit value.</returns>
        public static ForcePerLength?From(QuantityValue?value, ForcePerLengthUnit fromUnit)
        {
            if (!value.HasValue)
            {
                return(null);
            }
            switch (fromUnit)
            {
            case ForcePerLengthUnit.CentinewtonPerMeter:
                return(FromCentinewtonsPerMeter(value.Value));

            case ForcePerLengthUnit.DecinewtonPerMeter:
                return(FromDecinewtonsPerMeter(value.Value));

            case ForcePerLengthUnit.KilogramForcePerMeter:
                return(FromKilogramsForcePerMeter(value.Value));

            case ForcePerLengthUnit.KilonewtonPerMeter:
                return(FromKilonewtonsPerMeter(value.Value));

            case ForcePerLengthUnit.MicronewtonPerMeter:
                return(FromMicronewtonsPerMeter(value.Value));

            case ForcePerLengthUnit.MillinewtonPerMeter:
                return(FromMillinewtonsPerMeter(value.Value));

            case ForcePerLengthUnit.NanonewtonPerMeter:
                return(FromNanonewtonsPerMeter(value.Value));

            case ForcePerLengthUnit.NewtonPerMeter:
                return(FromNewtonsPerMeter(value.Value));

            default:
                throw new NotImplementedException("fromUnit: " + fromUnit);
            }
        }
コード例 #20
0
        /// <summary>
        ///     Converts this ForcePerLength to another ForcePerLength with the unit representation <paramref name="unit" />.
        /// </summary>
        /// <returns>A ForcePerLength with the specified unit.</returns>
        public ForcePerLength ToUnit(ForcePerLengthUnit unit)
        {
            var convertedValue = AsBaseNumericType(unit);

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

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

            return(UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider));
        }
コード例 #25
0
ファイル: ForcePerLength.g.cs プロジェクト: schlips/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>
 /// <exception cref="ArgumentException">If value is NaN or Infinity.</exception>
 public ForcePerLength(double value, ForcePerLengthUnit unit)
 {
     _value = value;
     _unit  = unit;
 }
コード例 #26
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="culture">Culture to use for localization and number formatting.</param>
 /// <returns>String representation.</returns>
 public string ToString(ForcePerLengthUnit unit, [CanBeNull] Culture culture)
 {
     return(ToString(unit, culture, 2));
 }
コード例 #27
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(ForcePerLengthUnit unit)
 {
     return(ToString(unit, null, 2));
 }
コード例 #28
0
 public static string GetAbbreviation(ForcePerLengthUnit unit, [CanBeNull] Culture culture)
 {
     return(UnitSystem.GetCached(culture).GetDefaultAbbreviation(unit));
 }
コード例 #29
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(ForcePerLengthUnit unit)
 {
     return(GetAbbreviation(unit, null));
 }
コード例 #30
0
ファイル: ForcePerLength.g.cs プロジェクト: schlips/UnitsNet
        /// <summary>
        ///     Converts this Duration to another Duration with the unit representation <paramref name="unit" />.
        /// </summary>
        /// <returns>A Duration with the specified unit.</returns>
        public ForcePerLength ToUnit(ForcePerLengthUnit unit)
        {
            var convertedValue = GetValueAs(unit);

            return(new ForcePerLength(convertedValue, unit));
        }