Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ====================
- public static void CompileAndRun(string code)
- {
- CompilerParameters CompilerParams = new CompilerParameters();
- string outputDirectory = Directory.GetCurrentDirectory();
- CompilerParams.GenerateInMemory = true;
- CompilerParams.TreatWarningsAsErrors = false;
- CompilerParams.GenerateExecutable = true;
- CompilerParams.CompilerOptions = "/optimize";
- string[] references = { "System.dll", "System.Windows.Forms.dll", "System.Drawing.dll", "xNet.dll", "Bunifu_UI_v1.5.3.dll", "System.ComponentModel.dll" };
- CompilerParams.ReferencedAssemblies.AddRange(references);
- CSharpCodeProvider provider = new CSharpCodeProvider();
- CompilerResults compile = provider.CompileAssemblyFromSource(CompilerParams, code);
- if (compile.Errors.HasErrors)
- {
- string text = "Compile error: ";
- foreach (CompilerError ce in compile.Errors)
- {
- text += "rn" + ce.ToString();
- }
- throw new Exception(text);
- }
- ExpoloreAssembly(compile.CompiledAssembly);
- Module module = compile.CompiledAssembly.GetModules()[0];
- Type mt = null;
- MethodInfo methInfo = null;
- if (module != null)
- {
- mt = module.GetType("DynaCore.DynaCore");
- }
- if (mt != null)
- {
- methInfo = mt.GetMethod("Main");
- }
- if (methInfo != null)
- {
- Console.WriteLine(methInfo.Invoke(null, new object[] { "here in dyna code" }));
- }
- }
- static void ExpoloreAssembly(Assembly assembly)
- {
- Console.WriteLine("Modules in the assembly:");
- foreach (Module m in assembly.GetModules())
- {
- Console.WriteLine("{0}", m);
- foreach (Type t in m.GetTypes())
- {
- Console.WriteLine("t{0}", t.Name);
- foreach (MethodInfo mi in t.GetMethods())
- {
- Console.WriteLine("tt{0}", mi.Name);
- }
- }
- }
- ====================
- Код который хочу выполнить
- --
- MessageBox.Show("test");
- CompileAndRun("MessageBox.Show(\"test\");");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement