private
void
Compiler(
string
code)
... {
CompilerParameters vCompilerParameters = new CompilerParameters();
vCompilerParameters.GenerateExecutable = false;
vCompilerParameters.GenerateInMemory = true;
vCompilerParameters.ReferencedAssemblies.Add("System.Windows.Forms.dll");
string vSource =
"using System.Windows.Forms; " +
"public class Temp " +
"{ " +
" public void Test() " +
" { " +
" " + code + " " +
" } " +
"} ";
CompilerResults vCompilerResults =
CodeDomProvider.CreateProvider("CSharp").CompileAssemblyFromSource(vCompilerParameters, vSource);
Assembly vAssembly = vCompilerResults.CompiledAssembly;
object vTemp = vAssembly.CreateInstance("Temp");
MethodInfo vTest = vTemp.GetType().GetMethod("Test");
vTest.Invoke(vTemp, null);
}
string code = " int sum = 0; for(int i = 0; i < 100; i++) { sum += i; } MessageBox.Show(sum.ToString()); " ;
Compiler(code);
... {
CompilerParameters vCompilerParameters = new CompilerParameters();
vCompilerParameters.GenerateExecutable = false;
vCompilerParameters.GenerateInMemory = true;
vCompilerParameters.ReferencedAssemblies.Add("System.Windows.Forms.dll");
string vSource =
"using System.Windows.Forms; " +
"public class Temp " +
"{ " +
" public void Test() " +
" { " +
" " + code + " " +
" } " +
"} ";
CompilerResults vCompilerResults =
CodeDomProvider.CreateProvider("CSharp").CompileAssemblyFromSource(vCompilerParameters, vSource);
Assembly vAssembly = vCompilerResults.CompiledAssembly;
object vTemp = vAssembly.CreateInstance("Temp");
MethodInfo vTest = vTemp.GetType().GetMethod("Test");
vTest.Invoke(vTemp, null);
}
string code = " int sum = 0; for(int i = 0; i < 100; i++) { sum += i; } MessageBox.Show(sum.ToString()); " ;
Compiler(code);