Beispiel #1
0
        /// <summary>
        /// 拼接两个 Expression 。
        /// </summary>
        /// <typeparam name="T">表达式中的元素类型</typeparam>
        /// <param name="left">左边的 Expression</param>
        /// <param name="right">右边的 Expression</param>
        /// <param name="func">表达式拼接的具体逻辑</param>
        /// <returns>拼接完成的 Expression</returns>
        public static Expression <Func <T, bool> > MakeBinary <T>(this Expression <Func <T, bool> > left,
                                                                  Expression <Func <T, bool> > right, Func <Expression, Expression, Expression> func)
        {
            var data = Combinate(right.Parameters, left.Parameters).ToArray();

            if (left.Parameters.Count != right.Parameters.Count || !data.All(p => p.Key.Type == p.Value.Type))
            {
                throw new InvalidOperationException("Parameter error.");
            }

            right = ParameterReplace.Replace(right, data) as Expression <Func <T, bool> >;
            return(Expression.Lambda <Func <T, bool> >(func(left.Body, right.Body), left.Parameters));
        }
Beispiel #2
0
        /// <summary>
        /// Replaces the specified e.
        /// </summary>
        /// <param name="e">The e.</param>
        /// <param name="paramList">The param list.</param>
        /// <returns></returns>
        public static Expression Replace(Expression e, IEnumerable <KeyValuePair <ParameterExpression, ParameterExpression> > paramList)
        {
            var item = new ParameterReplace(paramList);

            return(item.Visit(e));
        }