When you do something like:
int[] items = whatever; IEnumerable<int> query = from item in items where item % 2 == 0 select item;
then the compiler will turn this into something like:
static bool Predicate(int item) { return item % 2 == 0; } ... IEnumerable<int> query = Enumerable.Where<int>(items, new Func<int, bool> (Predicate));
That is, the compiler generates IL for this method. When you create a query object at runtime, the object returned by Where holds the delegate in the predicate and, if necessary, executes the predicate.
But you can create an IL for the delegate at run time if you want. What you do is save the predicate body as an expression tree. At run time, the expression tree can be dynamically compiled into a new IL; basically, we run a very simplified compiler that knows how to generate IL for expression trees. Thus, you can change the details of the predicate at run time and recompile the predicate without recompiling the entire program.
The author of this comment uses "baking" as a slang for "generating dynamic light code."
source share