Now this has been bugging me for ages and it’s time to find out if it’s possible. I currently have a working CodeDom that can compile one class, but I have created a program with multiple classes that I want to compile with CodeDom. I’ve tried looking here:
CodeDom – Linking multiple classes within a single Assembly
^ No help…
and here:
http://msdn.microsoft.com/en-us/library/system.codedom.compiler.compilerparameters.aspx
^ Not much help…
So, is this possible? And if so, how specifically do I do it? How can I link my classes together and compile?
At the top of the CodeDOM tree, there is
CodeCompileUnit, which is roughly equivalent to a single C# source code file. When you useCompileAssemblyFromDom()to compile, it actually takes a collection ofCodeCompileUnits. This means you can easily compile multiple classes at once: just create a separateCodeCompileUnitfor each of them.But that’s not the only option,
CodeCompileUnit(just like a C# file) can contain multiple class declarations (indirectly throughCodeNamespace), so you could use that instead.