We want to give a user a graphical format to design conditional statements on some data. Our application would take that graphical format, translate it into C#, compile it, and run the conditional statement against some data, returning a Boolean.
The catch is that these conditional statements need to be written and compiled (and, of course, executed) at runtime, since we won’t be rebuilding the application each time the user creates a new conditional statement.
We thought about using LINQ expression trees, but a compiled LINQ expression tree can’t be saved, which means we need to recompile each time the conditional statement is going to be executed.
We think a better alternative is to use CodeDOM to compile the conditional statement as a .dll (they would be converted into a static method of a static class that takes, as a parameter, the data to run against the conditional statement). This allows us to save the compiled statement, and we could load and unload the .dll at runtime. Also, it’s easier to generate the C# if-statement than the LINQ expression tree.
Alternatively, we could use Roslyn to generate the .dll’s. This is reportedly faster than CodeDOM, but Roslyn is still in CTP.
Are there hidden pitfalls, or a general pattern for doing this, that we should know about? Aside from being very careful to generate only functions that test against data (and does not modify data or allow invoking any other functions), what else should we be careful about? Will loading and unloading (potentially hundreds of) these .dll’s cause issues? If each .dll is given its own unique namespace, will loading and unloading (potentially hundreds of) them leave artifacts?