How to convert an Expression> to a Predicate

前端 未结 3 1113
醉话见心
醉话见心 2021-01-30 10:32

I have a method that accepts an Expression> as a parameter. I would like to use it as a predicate in the List.Find() method, but I can\'t

3条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-30 11:05

    Func func = expression.Compile();
    Predicate pred = t => func(t);
    

    Edit: per the comments we have a better answer for the second line:

    Predicate pred = func.Invoke;
    

提交回复
热议问题