示例#1
0
        public decimal Sum(string predicate, IEnumerable conditionParameters)
        {
            Dictionary <string, object> parameters = new Dictionary <string, object>();
            int i = 1;

            foreach (var parameter in conditionParameters)
            {
                object p = parameter;

                // it is need for calculating linq
                IEnumerable enumerable = parameter as IEnumerable;
                if (enumerable != null && !(parameter is string))
                {
                    ArrayList list = new ArrayList();
                    foreach (var item in enumerable)
                    {
                        list.Add(item);
                    }
                    p = list;
                }

                parameters.Add(string.Format("p{0}", i), p);
                i++;
            }

            ExpressionFactory      factory = new ExpressionFactory(_context, typeof(T), parameters);
            Func <object, decimal> func    = factory.BuildArithmeticExpression(predicate);

            decimal result = _collection.Sum(val => func(val));

            return(result);
        }