在运行时编写和编译源代码?

时间:2012-09-28 05:28:38

标签: .net c#-4.0

  

可能重复:
  Compile and run dynamic code, without generating EXE?
  How to Compile the .cs file into .dll in C#.Net programtically?

在.NET 4.0中,我想执行以下操作。

  1. 在运行时写入cs文件。
  2. 在运行时编译cs文件。
  3. 在运行时创建这些文件的实例。
  4. 是否可能以及如何?

1 个答案:

答案 0 :(得分:3)

是。有可能的。要创建和编译类,可以使用CodeDOM。然后你可以创建实例在你的代码中使用它们。

你为什么要这样做?如果您可以提供更多信息,则可以提供更好的替代方案。

相关问题