Esempio n. 1
0
        private static object AvgHandler(object[] arguments)
        {
            var sum    = 0m;
            var array  = arguments.Length > 0 ? (arguments[0] as IEnumerable ?? new object[0]) : new object[0];
            var length = 0;

            foreach (var argument in array)
            {
                length++;
                if (argument.IsDigit())
                {
                    sum = GetAddToDecimalFunction(argument.GetType())(sum, argument);
                }
                else
                {
                    throw new UnsupportedFunctionCallException("avg", arguments.Select(x => x?.GetType()));
                }
            }
            if (length == 0)
            {
                throw new UnsupportedFunctionCallException("avg");
            }
            return(sum / length);
        }
Esempio n. 2
0
        private static object SumHandler(object[] arguments)
        {
            var array      = arguments.Length > 0 ? (arguments[0] as IEnumerable ?? new object[0]) : new object[0];
            var hasElement = false;
            var sum        = 0m;

            foreach (var argument in array)
            {
                hasElement = true;
                if (argument.IsDigit())
                {
                    sum = GetAddToDecimalFunction(argument.GetType())(sum, argument);
                }
                else
                {
                    throw new UnsupportedFunctionCallException("sum", arguments.Select(x => x?.GetType()));
                }
            }
            if (!hasElement)
            {
                throw new UnsupportedFunctionCallException("sum");
            }
            return(sum);
        }