Lambda expressions and how to combine them?

前端 未结 4 1365
执念已碎
执念已碎 2020-12-31 05:19

How can I combine two lambda expressions into one using an OR ?

I have tried the following but merging them requires me to pass parameters into the Expressio

4条回答
  •  无人及你
    2020-12-31 05:38

    Sound interesting ... I don't know much about lambda expression, but I found this article. Under PredicateBuilder Source Code is an example for or that works for me:

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

提交回复
热议问题