示例#1
0
        /// <summary>
        /// 拼接两个 <paramref name="System.Linq.Expression"/> ,两个 <paramref name="System.Linq.Expression"/> 的参数必须完全相同。
        /// </summary>
        /// <typeparam name="T">表达式中的元素类型</typeparam>
        /// <param name="left">左边的 <paramref name="System.Linq.Expression"/></param>
        /// <param name="right">右边的 <paramref name="System.Linq.Expression"/></param>
        /// <param name="func">表达式拼接的具体逻辑</param>
        /// <returns>拼接完成的 <paramref name="System.Linq.Expression"/></returns>
        public static LambdaExpression MakeBinary(this LambdaExpression left, LambdaExpression right, Func <Expression, Expression, Expression> func)
        {
            var data = Combinate(right.Parameters, left.Parameters).ToArray();

            right = ParameterReplace.Replace(right, data) as LambdaExpression;
            return(Expression.Lambda(func(left.Body, right.Body), left.Parameters.ToArray()));
        }
示例#2
0
        public static Expression Replace(Expression e, IEnumerable <KeyValuePair <ParameterExpression, ParameterExpression> > paramList)
        {
            var item = new ParameterReplace(paramList);

            return(item.Visit(e));
        }