Can I compile Multiple classes into one program with CodeDom?

眉间皱痕 提交于 2020-01-16 19:06:10

问题


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?


回答1:


At the top of the CodeDOM tree, there is CodeCompileUnit, which is roughly equivalent to a single C# source code file. When you use CompileAssemblyFromDom() to compile, it actually takes a collection of CodeCompileUnits. This means you can easily compile multiple classes at once: just create a separate CodeCompileUnit for each of them.

But that's not the only option, CodeCompileUnit (just like a C# file) can contain multiple class declarations (indirectly through CodeNamespace), so you could use that instead.



来源:https://stackoverflow.com/questions/14502819/can-i-compile-multiple-classes-into-one-program-with-codedom

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!