Expression.Or, The parameter 'item' is not in scope

前端 未结 5 1146
一整个雨季
一整个雨季 2021-02-09 00:23

I am trying to write a static function to Or two expressions, but recieve the following error:

The parameter \'item\' is not in scope.

Descrip

5条回答
  •  傲寒
    傲寒 (楼主)
    2021-02-09 00:51

    As already suggested, here you can find this very nice (working) code

    public static Expression> Or(this Expression> expr1, Expression> expr2)
    {
        var invokedExpr = Expression.Invoke(expr2, expr1.Parameters.Cast());
        return Expression.Lambda>(Expression.Or(expr1.Body, invokedExpr), expr1.Parameters);
    }
    

    that you can adapt to your needs and which isn't tied (IMHO) to LINQ.

提交回复
热议问题