Example #1
0
        private double AsBaseNumericType(PorousMediumPermeabilityUnit unit)
        {
            if (Unit == unit)
            {
                return(_value);
            }

            var baseUnitValue = AsBaseUnit();

            switch (unit)
            {
            case PorousMediumPermeabilityUnit.Darcy: return(baseUnitValue / 9.869233e-13);

            case PorousMediumPermeabilityUnit.Microdarcy: return((baseUnitValue / 9.869233e-13) / 1e-6d);

            case PorousMediumPermeabilityUnit.Millidarcy: return((baseUnitValue / 9.869233e-13) / 1e-3d);

            case PorousMediumPermeabilityUnit.SquareCentimeter: return(baseUnitValue / 1e-4);

            case PorousMediumPermeabilityUnit.SquareMeter: return(baseUnitValue);

            default:
                throw new NotImplementedException($"Can not convert {Unit} to {unit}.");
            }
        }
Example #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 PorousMediumPermeability(double value, PorousMediumPermeabilityUnit unit)
        {
            if (unit == PorousMediumPermeabilityUnit.Undefined)
            {
                throw new ArgumentException("The quantity can not be created with an undefined unit.", nameof(unit));
            }

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

            var converted = AsBaseNumericType(unit);

            return(Convert.ToDouble(converted));
        }
Example #4
0
// ReSharper restore VirtualMemberNeverOverriden.Global

        protected (double UnitsInBaseUnit, double Tolerence) GetConversionFactor(PorousMediumPermeabilityUnit unit)
        {
            return(unit switch
            {
                PorousMediumPermeabilityUnit.Darcy => (DarcysInOneSquareMeter, DarcysTolerance),
                PorousMediumPermeabilityUnit.Microdarcy => (MicrodarcysInOneSquareMeter, MicrodarcysTolerance),
                PorousMediumPermeabilityUnit.Millidarcy => (MillidarcysInOneSquareMeter, MillidarcysTolerance),
                PorousMediumPermeabilityUnit.SquareCentimeter => (SquareCentimetersInOneSquareMeter, SquareCentimetersTolerance),
                PorousMediumPermeabilityUnit.SquareMeter => (SquareMetersInOneSquareMeter, SquareMetersTolerance),
                _ => throw new NotSupportedException()
            });
Example #5
0
        /// <summary>
        ///     Converts this PorousMediumPermeability to another PorousMediumPermeability with the unit representation <paramref name="unit" />.
        /// </summary>
        /// <returns>A PorousMediumPermeability with the specified unit.</returns>
        public PorousMediumPermeability ToUnit(PorousMediumPermeabilityUnit unit)
        {
            var convertedValue = AsBaseNumericType(unit);

            return(new PorousMediumPermeability(convertedValue, unit));
        }
Example #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 PorousMediumPermeabilityUnit unit)
        {
            IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);

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

            return(UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider));
        }
Example #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(PorousMediumPermeabilityUnit 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 PorousMediumPermeability(double value, PorousMediumPermeabilityUnit 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 PorousMediumPermeability ToUnit(PorousMediumPermeabilityUnit unit)
        {
            var convertedValue = GetValueAs(unit);

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