Ejemplo n.º 1
0
        /// <summary>
        /// 或 expr1 or expr2
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="expr1"></param>
        /// <param name="expr2"></param>
        /// <returns></returns>
        public static Expression <Func <T, bool> > Or <T>(this Expression <Func <T, bool> > expr1, Expression <Func <T, bool> > expr2)
        {
            ParameterExpression  newParameter = Expression.Parameter(typeof(T), "c");
            NewExpressionVisitor visitor      = new NewExpressionVisitor(newParameter);

            var left  = visitor.Visit(expr1.Body);
            var right = visitor.Visit(expr2.Body);
            var body  = Expression.Or(left, right);

            return(Expression.Lambda <Func <T, bool> >(body, newParameter));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 非 !expr
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="expr"></param>
        /// <returns></returns>
        public static Expression <Func <T, bool> > Not <T>(this Expression <Func <T, bool> > expr)
        {
            ParameterExpression  newParameter = Expression.Parameter(typeof(T), "c");
            NewExpressionVisitor visitor      = new NewExpressionVisitor(newParameter);
            var temp = visitor.Visit(expr.Body);
            var body = Expression.Not(temp);

            return(Expression.Lambda <Func <T, bool> >(body, newParameter));
        }