示例#1
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 ElectricPotentialChangeRate(double value, ElectricPotentialChangeRateUnit unit)
        {
            if (unit == ElectricPotentialChangeRateUnit.Undefined)
            {
                throw new ArgumentException("The quantity can not be created with an undefined unit.", nameof(unit));
            }

            _value = Guard.EnsureValidNumber(value, nameof(value));
            _unit  = unit;
        }
示例#2
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 ElectricPotentialChangeRate(decimal value, ElectricPotentialChangeRateUnit unit)
        {
            if (unit == ElectricPotentialChangeRateUnit.Undefined)
            {
                throw new ArgumentException("The quantity can not be created with an undefined unit.", nameof(unit));
            }

            _value = value;
            _unit  = unit;
        }
示例#3
0
        private double AsBaseNumericType(ElectricPotentialChangeRateUnit unit)
        {
            if (Unit == unit)
            {
                return(_value);
            }

            var baseUnitValue = AsBaseUnit();

            switch (unit)
            {
            case ElectricPotentialChangeRateUnit.KilovoltPerHour: return((baseUnitValue * 3600) / 1e3d);

            case ElectricPotentialChangeRateUnit.KilovoltPerMicrosecond: return((baseUnitValue / 1E6) / 1e3d);

            case ElectricPotentialChangeRateUnit.KilovoltPerMinute: return((baseUnitValue * 60) / 1e3d);

            case ElectricPotentialChangeRateUnit.KilovoltPerSecond: return((baseUnitValue) / 1e3d);

            case ElectricPotentialChangeRateUnit.MegavoltPerHour: return((baseUnitValue * 3600) / 1e6d);

            case ElectricPotentialChangeRateUnit.MegavoltPerMicrosecond: return((baseUnitValue / 1E6) / 1e6d);

            case ElectricPotentialChangeRateUnit.MegavoltPerMinute: return((baseUnitValue * 60) / 1e6d);

            case ElectricPotentialChangeRateUnit.MegavoltPerSecond: return((baseUnitValue) / 1e6d);

            case ElectricPotentialChangeRateUnit.MicrovoltPerHour: return((baseUnitValue * 3600) / 1e-6d);

            case ElectricPotentialChangeRateUnit.MicrovoltPerMicrosecond: return((baseUnitValue / 1E6) / 1e-6d);

            case ElectricPotentialChangeRateUnit.MicrovoltPerMinute: return((baseUnitValue * 60) / 1e-6d);

            case ElectricPotentialChangeRateUnit.MicrovoltPerSecond: return((baseUnitValue) / 1e-6d);

            case ElectricPotentialChangeRateUnit.MillivoltPerHour: return((baseUnitValue * 3600) / 1e-3d);

            case ElectricPotentialChangeRateUnit.MillivoltPerMicrosecond: return((baseUnitValue / 1E6) / 1e-3d);

            case ElectricPotentialChangeRateUnit.MillivoltPerMinute: return((baseUnitValue * 60) / 1e-3d);

            case ElectricPotentialChangeRateUnit.MillivoltPerSecond: return((baseUnitValue) / 1e-3d);

            case ElectricPotentialChangeRateUnit.VoltPerHour: return(baseUnitValue * 3600);

            case ElectricPotentialChangeRateUnit.VoltPerMicrosecond: return(baseUnitValue / 1E6);

            case ElectricPotentialChangeRateUnit.VoltPerMinute: return(baseUnitValue * 60);

            case ElectricPotentialChangeRateUnit.VoltPerSecond: return(baseUnitValue);

            default:
                throw new NotImplementedException($"Can not convert {Unit} to {unit}.");
            }
        }
示例#4
0
        /// <summary>
        ///     Convert to the unit representation <paramref name="unit" />.
        /// </summary>
        /// <returns>Value converted to the specified unit.</returns>
        public double As(ElectricPotentialChangeRateUnit unit)
        {
            if (Unit == unit)
            {
                return(Convert.ToDouble(Value));
            }

            var converted = AsBaseNumericType(unit);

            return(Convert.ToDouble(converted));
        }
示例#5
0
        /// <summary>
        ///     Converts this ElectricPotentialChangeRate to another ElectricPotentialChangeRate with the unit representation <paramref name="unit" />.
        /// </summary>
        /// <returns>A ElectricPotentialChangeRate with the specified unit.</returns>
        public ElectricPotentialChangeRate ToUnit(ElectricPotentialChangeRateUnit unit)
        {
            var convertedValue = AsBaseNumericType(unit);

            return(new ElectricPotentialChangeRate(convertedValue, unit));
        }
示例#6
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 ElectricPotentialChangeRateUnit unit)
        {
            IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);

            return(UnitParser.Default.TryParse <ElectricPotentialChangeRateUnit>(str, provider, out unit));
        }
示例#7
0
 public static bool TryParseUnit(string str, out ElectricPotentialChangeRateUnit unit)
 {
     return(TryParseUnit(str, null, out unit));
 }
示例#8
0
 public static ElectricPotentialChangeRate From(double value, ElectricPotentialChangeRateUnit fromUnit)
 {
     return(new ElectricPotentialChangeRate((double)value, fromUnit));
 }
示例#9
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(ElectricPotentialChangeRateUnit unit, [CanBeNull] string cultureName)
        {
            IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);

            return(UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider));
        }
示例#10
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(ElectricPotentialChangeRateUnit unit)
 {
     return(GetAbbreviation(unit, null));
 }
 /// <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 ElectricPotentialChangeRate(double value, ElectricPotentialChangeRateUnit unit)
 {
     _value = value;
     _unit  = unit;
 }
        /// <summary>
        ///     Converts this Duration to another Duration with the unit representation <paramref name="unit" />.
        /// </summary>
        /// <returns>A Duration with the specified unit.</returns>
        public ElectricPotentialChangeRate ToUnit(ElectricPotentialChangeRateUnit unit)
        {
            var convertedValue = GetValueAs(unit);

            return(new ElectricPotentialChangeRate(convertedValue, unit));
        }
 /// <summary>
 ///     Convert to the unit representation <paramref name="unit" />.
 /// </summary>
 /// <returns>Value converted to the specified unit.</returns>
 public double As(ElectricPotentialChangeRateUnit unit) => GetValueAs(unit);