Example #1
0
        static void CompileWithSimple(string[] args)
        {
            CompuMaster.JitCompilation.BaseInMemoryCompiler cscInMemory =
                new CompuMaster.JitCompilation.CSharpInMemoryCompiler();
            string src = "public class TestClass {public static string Answer() {return \"Hello World from inside of a dynamically created assembly!\";}}";

            CompuMaster.JitCompilation.CompileResults cResult = cscInMemory.Compile(src, false);
            System.Console.WriteLine((string)cResult.Invoke("TestClass", "Answer", null)); // will result: "Hello World!"
        }
Example #2
0
        static void CompileWithError(string[] args)
        {
            CompuMaster.JitCompilation.BaseInMemoryCompiler cscInMemory = new CompuMaster.JitCompilation.CSharpInMemoryCompiler();
            string src = "public class CmTestCompiler {public static string Answer() {return \"\"Hello World from inside of a dynamically created assembly!\";}}";

            CompuMaster.JitCompilation.CompileResults cResult = cscInMemory.Compile(src, false);
            if ((cResult.CompilerErrors != null) && (cResult.CompilerErrors.HasErrors == false))
            {
                System.Console.WriteLine("Compiled successfully, this is the result:");
                System.Console.WriteLine((string)cResult.Invoke("CmTestCompiler", "Answer", null)); // will result: "Hello World from inside of a dynamically created assembly!"
            }
            else
            {
                System.Console.WriteLine("Compilation failed:");
                foreach (System.CodeDom.Compiler.CompilerError cError in cResult.CompilerErrors)
                {
                    System.Console.WriteLine(cError.ToString());
                }
            }
        }