Possible Duplicate:
Is there an easy way to parse a (lambda expression) string into an Action delegate?
I would like to store lambda expressions as strings in a config file and at runtime dynamically load these strings into lambda expressions in C#. My objective is to configure and inject rules. Any utilities available for creating lambda expressions from a string ?
Are there any other light weight solutions for the same objective ?
Have a look at Dynamic Linq. It's an old post but always useful.
If you know the type of the expressions ahead of time, then you can compile them as part of a class then pull them back out from the resulting assembly.
Here's an example that does (with the expressions taking a string and returning a bool) that and runs the resulting rules.
With the contents of c:\temp\rules.txt being this:
Then the resulting output is this:
Source: