Esempio n. 1
0
        /// <summary>
        /// Given ConvertModel returns collection of possible results.
        /// </summary>
        /// <returns>The converted value as a double.</returns>
        public static IEnumerable <UnitConversionResult> Convert(ConvertModel convertModel)
        {
            var results = new List <UnitConversionResult>();

            foreach (QuantityType quantityType in _included)
            {
                double convertedValue = UnitHandler.ConvertInput(convertModel, quantityType);

                if (!double.IsNaN(convertedValue))
                {
                    UnitConversionResult result = new UnitConversionResult(Round(convertedValue), convertModel.ToUnit, quantityType);
                    results.Add(result);
                }
            }

            return(results);
        }
Esempio n. 2
0
        public List <Result> Query(Query query)
        {
            if (query == null)
            {
                throw new ArgumentNullException(paramName: nameof(query));
            }

            // Parse
            ConvertModel convertModel = InputInterpreter.Parse(query);

            if (convertModel == null)
            {
                return(new List <Result>());
            }

            // Convert
            return(UnitHandler.Convert(convertModel)
                   .Select(x => GetResult(x))
                   .ToList());
        }