The other day I was discussing code generation with a collegue and he was discussing a hyperthetical siuation where it would be possible to create source code at runtime and even compile it to create apps at runtime. Now I didnt know much about this, but I decided to have a little exploratory look into this. As ever .NET amazed me (again) and had 2 interesting namespaces to do this.
System.CodeDom: Which allows the generation of a
CodeCompileUnitwhich can be then generated into a source code file for any .NET language
System.CodeDom.Compiler: Is able to create a Assembly/Exe at runtime from a source code file.
I have written a small demo application and an accompanying article about this over at http://www.codeproject.com, this is available right here, if you are interested. This is what it looks like anyway:
The application creates a simple source code file and compiles it into an Exe and runs it, all at runtime. Cool.