Ejemplo n.º 1
0
        /// <summary>
        /// Dynamically constructs a quantity of the given <see cref="QuantityInfo"/> with the value in the quantity's base units.
        /// </summary>
        /// <param name="quantityInfo">The <see cref="QuantityInfo"/> of the quantity to create.</param>
        /// <param name="value">The value to construct the quantity with.</param>
        /// <returns>The created quantity.</returns>
        public static IQuantity FromQuantityInfo(QuantityInfo quantityInfo, QuantityValue value)
        {
            switch (quantityInfo.Name)
            {
            case "Depth":
                return(Depth.From(value, Depth.BaseUnit));

            case "Jerk":
                return(Jerk.From(value, Jerk.BaseUnit));

            default:
                throw new ArgumentException($"{quantityInfo.Name} is not a supported quantity.");
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        ///     Try to dynamically construct a quantity.
        /// </summary>
        /// <param name="value">Numeric value.</param>
        /// <param name="unit">Unit enum value.</param>
        /// <param name="quantity">The resulting quantity if successful, otherwise <c>default</c>.</param>
        /// <returns><c>True</c> if successful with <paramref name="quantity"/> assigned the value, otherwise <c>false</c>.</returns>
        public static bool TryFrom(QuantityValue value, Enum unit, out IQuantity quantity)
        {
            switch (unit)
            {
            case DepthUnit depthUnit:
                quantity = Depth.From(value, depthUnit);
                return(true);

            case JerkUnit jerkUnit:
                quantity = Jerk.From(value, jerkUnit);
                return(true);

            default:
            {
                quantity = default(IQuantity);
                return(false);
            }
            }
        }