How does it work?

The code you select gets wrapped inside it's own class (unless it contains a class of its own) and then an entry point is added to this class. A bunch of common imports (i.e. include) statements are added, just in case.

It's compiled using System.CodeDom.Compiler which is remarkably easy to do.

If the code doesn't compile -- then I display a mini window, showing the generated code, and what compilation errors there were. This gives you a chance to alter the code and get it to work.

If there's a runtime exception, then I display the same window, along with the exception that occurred.