iTz_Mercury

C# Codedom Class [original]

May 21st, 2012
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.36 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.CodeDom.Compiler;
  5. using System.Windows.Forms;
  6.  
  7.     class CodeDom
  8.     {
  9.         public static bool Compile(string EXE_Name, string[] Source)
  10.         {
  11.             CodeDomProvider Compiler = CodeDomProvider.CreateProvider("CSharp");
  12.             CompilerParameters Parameters = new CompilerParameters();
  13.             CompilerResults cResults = default(CompilerResults);
  14.  
  15.             Parameters.GenerateExecutable = true;
  16.             Parameters.OutputAssembly = EXE_Name;
  17.             Parameters.ReferencedAssemblies.Add("System.dll");
  18.             Parameters.CompilerOptions = " /target:winexe";
  19.             Parameters.TreatWarningsAsErrors = false;
  20.  
  21.             cResults = Compiler.CompileAssemblyFromSource(Parameters, Source);
  22.  
  23.             if (cResults.Errors.Count > 0)
  24.             {
  25.                 foreach (CompilerError CompilerError_loopVariable in cResults.Errors)
  26.                 {
  27.                     CompilerError error = CompilerError_loopVariable;
  28.                     MessageBox.Show("Error: " + error.ErrorText, "", MessageBoxButtons.OK, MessageBoxIcon.Error);
  29.                 }
  30.                 return false;
  31.             }
  32.             else if (cResults.Errors.Count == 0)
  33.             {
  34.                 return true;
  35.             }
  36.             return true;
  37.         }
  38.     }
Advertisement
Add Comment
Please, Sign In to add comment