Exemple #1
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="AmplitudeRatioUnit" /> to <see cref="AmplitudeRatio" />.
        /// </summary>
        /// <param name="value">Value to convert from.</param>
        /// <param name="fromUnit">Unit to convert from.</param>
        /// <returns>AmplitudeRatio unit value.</returns>
        public static AmplitudeRatio?From(double?value, AmplitudeRatioUnit fromUnit)
        {
            if (!value.HasValue)
            {
                return(null);
            }
            switch (fromUnit)
            {
            case AmplitudeRatioUnit.DecibelMicrovolt:
                return(FromDecibelMicrovolts(value.Value));

            case AmplitudeRatioUnit.DecibelMillivolt:
                return(FromDecibelMillivolts(value.Value));

            case AmplitudeRatioUnit.DecibelUnloaded:
                return(FromDecibelsUnloaded(value.Value));

            case AmplitudeRatioUnit.DecibelVolt:
                return(FromDecibelVolts(value.Value));

            default:
                throw new NotImplementedException("fromUnit: " + fromUnit);
            }
        }
        public static AmplitudeRatio From(QuantityValue value, AmplitudeRatioUnit fromUnit)
#endif
        {
            return(new AmplitudeRatio((double)value, fromUnit));
        }
 public static AmplitudeRatio From(double value, AmplitudeRatioUnit fromUnit)
 /// <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(AmplitudeRatioUnit unit)
 {
     return(ToString(unit, null, 2));
 }
        /// <summary>
        ///     Converts this AmplitudeRatio to another AmplitudeRatio with the unit representation <paramref name="unit" />.
        /// </summary>
        /// <returns>A AmplitudeRatio with the specified unit.</returns>
        public AmplitudeRatio ToUnit(AmplitudeRatioUnit unit)
        {
            var convertedValue = AsBaseNumericType(unit);

            return(new AmplitudeRatio(convertedValue, unit));
        }
 public static string GetAbbreviation(AmplitudeRatioUnit unit)
 {
     return(GetAbbreviation(unit, null));
 }
 /// <summary>
 ///     Convert to the unit representation <paramref name="unit" />.
 /// </summary>
 /// <returns>Value converted to the specified unit.</returns>
 public double As(AmplitudeRatioUnit unit) => GetValueAs(unit);
 public static bool TryParseUnit(string str, out AmplitudeRatioUnit unit)
 {
     return(TryParseUnit(str, null, out unit));
 }
Exemple #9
0
 public string ToString(AmplitudeRatioUnit unit, CultureInfo culture, string format, params object[] args)
 {
     return(string.Format(culture, format, UnitFormatter.GetFormatArgs(unit, As(unit), culture, args)));
 }
Exemple #10
0
        public static string GetAbbreviation(
            AmplitudeRatioUnit unit,
#if WINDOWS_UWP
            [CanBeNull] string cultureName)
Exemple #11
0
 public string ToString(AmplitudeRatioUnit unit, CultureInfo culture = null, int significantDigitsAfterRadix = 2)
 {
     return(ToString(unit, culture, UnitFormatter.GetFormat(As(unit), significantDigitsAfterRadix)));
 }
Exemple #12
0
 public static string GetAbbreviation(AmplitudeRatioUnit unit, CultureInfo culture = null)
 {
     return(UnitSystem.GetCached(culture).GetDefaultAbbreviation(unit));
 }
Exemple #13
0
 public static AmplitudeRatio From(decimal value, AmplitudeRatioUnit fromUnit)
 {
     return(new AmplitudeRatio((decimal)value, fromUnit));
 }
        /// <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(AmplitudeRatioUnit unit, [CanBeNull] string cultureName)
        {
            IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);

            return(UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider));
        }
        /// <summary>
        ///     Converts this Duration to another Duration with the unit representation <paramref name="unit" />.
        /// </summary>
        /// <returns>A Duration with the specified unit.</returns>
        public AmplitudeRatio ToUnit(AmplitudeRatioUnit unit)
        {
            var convertedValue = GetValueAs(unit);

            return(new AmplitudeRatio(convertedValue, unit));
        }
 public static AmplitudeRatio From(double value, AmplitudeRatioUnit fromUnit)
 {
     return(new AmplitudeRatio((double)value, fromUnit));
 }
 /// <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 AmplitudeRatio(double value, AmplitudeRatioUnit unit)
 {
     _value = value;
     _unit  = unit;
 }
        /// <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 AmplitudeRatioUnit unit)
        {
            IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);

            return(UnitParser.Default.TryParse <AmplitudeRatioUnit>(str, provider, out unit));
        }
        public static string GetAbbreviation(AmplitudeRatioUnit unit, [CanBeNull] IFormatProvider provider)
        {
            provider = provider ?? UnitSystem.DefaultCulture;

            return(UnitSystem.GetCached(provider).GetDefaultAbbreviation(unit));
        }
 /// <summary>
 ///     Dynamically convert from value and unit enum <see cref="AmplitudeRatioUnit" /> to <see cref="AmplitudeRatio" />.
 /// </summary>
 /// <param name="value">Value to convert from.</param>
 /// <param name="fromUnit">Unit to convert from.</param>
 /// <returns>AmplitudeRatio unit value.</returns>
 public static AmplitudeRatio?From(QuantityValue?value, AmplitudeRatioUnit fromUnit)
 {
     return(value.HasValue ? new AmplitudeRatio((double)value.Value, fromUnit) : default(AmplitudeRatio?));
 }
 /// <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(AmplitudeRatioUnit unit, [CanBeNull] IFormatProvider provider)
 {
     return(ToString(unit, provider, 2));
 }
Exemple #22
0
 public static string GetAbbreviation(AmplitudeRatioUnit unit, [CanBeNull] Culture culture)
 {
     return(UnitSystem.GetCached(culture).GetDefaultAbbreviation(unit));
 }
 AmplitudeRatio(double numericValue, AmplitudeRatioUnit unit)
 {
     _value = numericValue;
     _unit  = unit;
 }
Exemple #24
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(AmplitudeRatioUnit unit, [CanBeNull] Culture culture)
 {
     return(ToString(unit, culture, 2));
 }
Exemple #25
0
 public static void HasConversion(this PropertyBuilder <AmplitudeRatio> propertyBuilder, AmplitudeRatioUnit unit) =>
 propertyBuilder.HasConversion(v => v.As(unit), v => new AmplitudeRatio(v, unit));