Advertisement
ozakisama

HAHAHA

Oct 24th, 2014
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.56 KB | None | 0 0
  1. using System;
  2. using System.Collections;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using Microsoft.CSharp;
  6. using System.CodeDom.Compiler;
  7. using System.Reflection;
  8. using System.Diagnostics;
  9. using System.IO;
  10. using System.Threading;
  11.  
  12. namespace VariableDeclarationFinal
  13. {
  14.     class CompileCode
  15.     {
  16.         private static string MyCode(string decleration, string appName)
  17.         {
  18.             return "using System;\n namespace " + appName + "\n{\npublic class " + appName + "\n{" +
  19.                    "public static void Main(string[] args)\n{\n\t\t" +
  20.                    decleration + "\nConsole.ReadLine();\n}\n}\n}";
  21.         }
  22.  
  23.         public static bool DebugProgram(string text)
  24.         {
  25.             string appName = "lololol";
  26.             string decleration = MyCode(text, appName);
  27.             bool result = false;
  28.             CSharpCodeProvider codeProvider = new CSharpCodeProvider();
  29.             ICodeCompiler compiler = codeProvider.CreateCompiler();
  30.             CompilerParameters parameters = new CompilerParameters();
  31.             parameters.GenerateExecutable = true;
  32.             parameters.GenerateInMemory = true;
  33.             parameters.IncludeDebugInformation = true;
  34.  
  35.             parameters.OutputAssembly = @"C:\Users\" + Environment.UserName + "\\Desktop\\" + appName + ".exe";
  36.             parameters.MainClass = appName + "." + appName;
  37.             foreach (Assembly asm in AppDomain.CurrentDomain.GetAssemblies())
  38.             {
  39.                 parameters.ReferencedAssemblies.Add(asm.Location);
  40.             }
  41.             String code = decleration.ToString();
  42.             CompilerResults results = compiler.CompileAssemblyFromSource(parameters, code);
  43.             if (results.Errors.Count > 0)
  44.             {
  45.                 result = false;
  46.             }
  47.             else
  48.             {
  49.                 try
  50.                 {
  51.                     result = true;
  52.                 }
  53.                 catch { }
  54.             }
  55.             return result;
  56.         }
  57.     }
  58. }
  59.  
  60.  
  61. ===============================================
  62.  
  63.  
  64. while (args != null)
  65.             {
  66.                 string text = Console.ReadLine();
  67.                 if (CompileCode.DebugProgram(text))
  68.                 {
  69.                     Console.ForegroundColor = ConsoleColor.Magenta;
  70.                     Console.WriteLine("Valid");
  71.                 }
  72.                 else
  73.                 {
  74.                     Console.ForegroundColor = ConsoleColor.Red;
  75.                     Console.WriteLine("Invalid");
  76.                 }
  77.                 Console.ResetColor();
  78.             }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement