Just remove the first line and the
@"
at the beginning of the second line, and the
";
at the end of line 9. You can then rename the file to whatever source name you need, and compile it.
The final text should be:
using System;
namespace Test{
public class TestClass {
public TestClass() {}
}
}
CSharpCodeProvider provider = new CSharpCodeProvider();
CompilerParameters cp = new CompilerParameters();
cp.GenerateInMemory = true;
cp.GenerateExecutable = false;
CompilerResults cr =
provider.CompileAssemblyFromSource(cp, src);
if (cr.Errors.Count > 0)
{
foreach (CompilerError ce in cr.Errors)
{
Console.WriteLine(ce.ErrorText);
}
}
else
{
Type t = cr.CompiledAssembly.GetType("Test.TestClass");
object o = Activator.CreateInstance(t);
}