Home of the AlmostImplementedException

Compile code at runtime

Sometimes it is necessary to compile code explicitly at runtime. For example you can create a small user defined shell. Today I will show you how this can be done.
At first we need the following: MemoryStream, StreamWriter and namespaces System.Reflection and System.CodeDom.Compiler.
This works as follows: Define a source code that will be compiled in memory with the following method. To ease the work you can predefine namespaces, functions, etc. In my snippet I created a Windows-Forms-Project. For that reason I intentionally make use of MessageBox.

Share :

, , , , ,

Comments are currently closed.