続き

// CSharpExecuter.Testクラス
public Assembly CompileAssemblyToMemory(params string[] source)
{
using (Microsoft.CSharp.CSharpCodeProvider provider = new Microsoft.CSharp.CSharpCodeProvider())
{
CompilerParameters parameters = new CompilerParameters();
parameters.GenerateExecutable = false;
parameters.GenerateInMemory = true;
parameters.TreatWarningsAsErrors = false;

CompilerResults result = provider.CompileAssemblyFromSource(parameters, source);
if (result.Errors.Count == 0)
{
return result.CompiledAssembly;
}
else
{
string message = string.Empty;
foreach (CompilerError error in result.Errors)
{
message += error.ErrorText + "\r\n";
}
throw new ApplicationException(message);
}
}
}