protected static Assembly GetResult(string input) { var parser = Parser.CreateParser(input); var @class = parser.prog(); var assemblyName = ("Output_" + Guid.NewGuid().ToString("N") + ".exe"); var compilerContext = new CompilerContext(new ClrCodeGenerator(assemblyName), new ErrorSet()); @class.Compile(compilerContext); return compilerContext.Save(false); }
private static bool GetResult(string expression) { var input = @"public class Test { public bool TestMethodName(){ return " + expression + ";} }"; var parser = Parser.CreateParser(input); var @class = parser.prog(); var assemblyName = ("Output_" + Guid.NewGuid().ToString("N") + ".exe"); var compilerContext = new CompilerContext(new ClrCodeGenerator(assemblyName), new ErrorSet()); @class.Compile(compilerContext); var outputAssembly = compilerContext.Save(false); Type type = outputAssembly.GetType("Test"); MethodInfo main = type.GetMethod("TestMethodName"); return (bool)main.Invoke(null, null); }