我尝试使用CSharpCodeProvider编译C#代码(没有太复杂,只有Main())。此代码返回一个字符串,但我无法理解如何将此值传递给我的函数。有可能吗?
public string Execute(List<String> code, List<String> _referencedAssemblies)
{
CompilerParameters cp = new CompilerParameters();
for (int i = 0; i < _referencedAssemblies.Count; i++) {
cp.ReferencedAssemblies.Add(_referencedAssemblies[i]);
}
StringBuilder sb = new StringBuilder();
for (int i = 0; i < code.Count; i++) {
sb.Append(code[i]);
}
CSharpCodeProvider provider = new CSharpCodeProvider();
CompilerResults result = provider.CompileAssemblyFromSource(cp, sb.ToString());