using (CSharpCodeProvider provider = new CSharpCodeProvider())
{
CompilerParameters options = new CompilerParameters();
options.GenerateInMemory = true;
CompilerResults result = provider.CompileAssemblyFromSource(options, sb.ToString());
if (result.Errors.HasErrors)
{
StringBuilder str = new StringBuilder();
foreach (CompilerError eoor in result.Errors)
{
str.AppendFormat("{0} {1}", eoor.Line, eoor.ErrorText);
}
Console.WriteLine(str.ToString());
}
else
{
Console.WriteLine("Compile finished");
Type codeType = result.CompiledAssembly.GetType("Driver");
codeType.InvokeMember("Run", BindingFlags.InvokeMethod | BindingFlags.Static | BindingFlags.Public, null, null, null);
}
}
CSharpCodeProvider 學習 c#
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.