Convert an Expression<Func<T,bool>> to a Func<T,Bool>

Posted on 2010-03-24
Medium Priority
Last Modified: 2012-08-13
I'm using Dynamic LINQ and need to be able to query a BindingList.  However, the Where<> on the BindingList accepts a Func<T,bool> and I have an Expression<Func<T,bool>>.

How can I convert the Expression<Func<T,bool>> to Func<T, bool>?
Question by:jpmc_cmsops
LVL 18

Accepted Solution

Richard Lee earned 2000 total points
ID: 28453233
Try using the compile.

// test scenario
Expression<Func<int, bool>> exp = null;
Func<int, bool> func = null;

func = exp.Compile();


Author Closing Comment

ID: 31706562
Awesome.  That worked.  I didn't even see that in my list of options on the Expression object originally.


Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Enter Foreign and Special Characters Enter characters you can't find on a keyboard using its ASCII code ... and learn how to make a handy reference for yourself using Excel ~ Use these codes in any Windows application! ... whether it is a Micr…
Suggested Courses

607 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question