Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections;
- using System.ComponentModel;
- using System.Data;
- using Microsoft.CSharp;
- using System.CodeDom.Compiler;
- using System.Reflection;
- using System.Diagnostics;
- using System.IO;
- using System.Threading;
- namespace VariableDeclarationFinal
- {
- class CompileCode
- {
- private static string MyCode(string decleration, string appName)
- {
- return "using System;\n namespace " + appName + "\n{\npublic class " + appName + "\n{" +
- "public static void Main(string[] args)\n{\n\t\t" +
- decleration + "\nConsole.ReadLine();\n}\n}\n}";
- }
- public static bool DebugProgram(string text)
- {
- string appName = "lololol";
- string decleration = MyCode(text, appName);
- bool result = false;
- CSharpCodeProvider codeProvider = new CSharpCodeProvider();
- ICodeCompiler compiler = codeProvider.CreateCompiler();
- CompilerParameters parameters = new CompilerParameters();
- parameters.GenerateExecutable = true;
- parameters.GenerateInMemory = true;
- parameters.IncludeDebugInformation = true;
- parameters.OutputAssembly = @"C:\Users\" + Environment.UserName + "\\Desktop\\" + appName + ".exe";
- parameters.MainClass = appName + "." + appName;
- foreach (Assembly asm in AppDomain.CurrentDomain.GetAssemblies())
- {
- parameters.ReferencedAssemblies.Add(asm.Location);
- }
- String code = decleration.ToString();
- CompilerResults results = compiler.CompileAssemblyFromSource(parameters, code);
- if (results.Errors.Count > 0)
- {
- result = false;
- }
- else
- {
- try
- {
- result = true;
- }
- catch { }
- }
- return result;
- }
- }
- }
- ===============================================
- while (args != null)
- {
- string text = Console.ReadLine();
- if (CompileCode.DebugProgram(text))
- {
- Console.ForegroundColor = ConsoleColor.Magenta;
- Console.WriteLine("Valid");
- }
- else
- {
- Console.ForegroundColor = ConsoleColor.Red;
- Console.WriteLine("Invalid");
- }
- Console.ResetColor();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement