3 回答

TA贡献1815条经验 获得超6个赞
一种不建议使用的方法(使用.NET 4.0作为前面提到的海报):
using System.CodeDom.Compiler;
using System.Reflection;
using System;
public class J
{
public static void Main()
{
System.CodeDom.Compiler.CompilerParameters parameters = new CompilerParameters();
parameters.GenerateExecutable = false;
parameters.OutputAssembly = "AutoGen.dll";
CompilerResults r = CodeDomProvider.CreateProvider("CSharp").CompileAssemblyFromSource(parameters, "public class B {public static int k=7;}");
//verify generation
Console.WriteLine(Assembly.LoadFrom("AutoGen.dll").GetType("B").GetField("k").GetValue(null));
}
}
- 3 回答
- 0 关注
- 578 浏览
添加回答
举报