Example #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>
        public static LambdaExpression MakeBinary(this LambdaExpression left, LambdaExpression right, Func <Expression, Expression, Expression> func)
        {
            if (right?.Body == null)
            {
                throw new ArgumentNullException(nameof(right));
            }

            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()));
        }
Example #2
0
        public static Expression Replace(Expression e, IEnumerable <KeyValuePair <ParameterExpression, ParameterExpression> > paramList)
        {
            var item = new ParameterReplace(paramList);

            return(item.Visit(e));
        }