示例#1
0
        /// <summary>
        /// 拼接两个 <paramref>
        ///        <name>System.Linq.Expression</name>
        ///      </paramref>  ,两个 <paramref>
        ///                         <name>System.Linq.Expression</name>
        ///                       </paramref>  的参数必须完全相同。
        /// </summary>
        /// <param name="left">左边的 <paramref>
        ///                          <name>System.Linq.Expression</name>
        ///                        </paramref> </param>
        /// <param name="right">右边的 <paramref>
        ///                           <name>System.Linq.Expression</name>
        ///                         </paramref> </param>
        /// <param name="func">表达式拼接的具体逻辑</param>
        /// <returns>拼接完成的 <paramref>
        ///                  <name>System.Linq.Expression</name>
        ///                </paramref> </returns>
        private 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));
        }