public void setCompilerEnvironment()
        {
            var o2Timer = new O2Timer("Code Compiled in");

            this.csharpCompiler(new CSharp_FastCompiler());

            this.csharpCompiler().set_BeforeSnippetAst(() => this.csharpCompiler().invocationParameters(this.InvocationParameters));

            this.csharpCompiler().set_OnAstFail(() =>
                {
                    //"AST creation failed".error();
                    //	this.sourceCodeViewer.enabled(false);
                    executeButton.enabled(false);
                    result_RichTextBox.textColor(Color.Red).set_Text("Ast Parsing Errors:\r\n\r\n");
                    //.append_Text(csharpCompiler.AstErrors);
                    commandsToExecute.updateCodeComplete(this.csharpCompiler());
                    sourceCodeViewer.setDocumentContents(this.csharpCompiler().sourceCode());
                    OnAstFail.invoke();
                });

            this.csharpCompiler().set_OnAstOK(() =>
                {
                    o2Timer.start();
                    commandsToExecute.editor().refresh();
                    sourceCodeViewer.enabled(true);
                    commandsToExecute.invokeOnThread(() => commandsToExecute.Refresh());
                    GeneratedCode = this.csharpCompiler().sourceCode();
                    commandsToExecute.updateCodeComplete(this.csharpCompiler());
                    sourceCodeViewer.setDocumentContents(this.csharpCompiler().sourceCode());
                    OnAstOK.invoke();
                });

            this.csharpCompiler().set_OnCompileFail(() =>
               {
                   //"AST OK, but compilation failed".error();
                   executeButton.enabled(false);
                   var codeOffset = this.csharpCompiler().getGeneratedSourceCodeMethodLineOffset();
                   this.csharpCompiler().compilationErrors().runForEachCompilationError(
                                             (row, col) =>
                                             {
                                                 sourceCodeViewer.editor().setSelectedText(row, col, true, false);
                                                 commandsToExecute.editor().setSelectedText(
                                                     row - codeOffset.Line,
                                                     col - codeOffset.Column,
                                                     true, /*showAsError*/
                                                     false, /*showAsBookMark*/
                                                     false); /*decrementLineAndColumn*/

                                             });
                   result_RichTextBox.textColor(Color.Red)
                                     .set_Text("Compilation Errors:\r\n\r\n")
                                     .append_Text(this.csharpCompiler().compilationErrors());
                   onCompileFail.invoke();

               });
            this.csharpCompiler().set_OnCompileOK(() =>
               {
                   o2Timer.stop();
                   "Compilation OK".debug();
                   commandsToExecute.editor().refresh();
                   sourceCodeViewer.editor().refresh();
                   result_RichTextBox.set_Text("Compilation OK:\r\n\r\n")
                                          .textColor(Color.Green);
                   executeButton.enabled(true);
                   if (AutoSaveOnCompileSuccess && Code != defaultCode)
                   {
                       AutoSaveDir.createDir();    // make sure it exits
                       var targetFile = AutoSaveDir.pathCombine(Files.getFileSaveDateTime_Now().trim() + ".cs");
                       targetFile.fileWrite(Code);
                   }

                   onCompileOK.invoke();
                   // once all is done update the codeComplete information
                   if (commandsToExecute.editor().o2CodeCompletion.notNull())
                       commandsToExecute.editor().o2CodeCompletion.addReferences(this.csharpCompiler().referencedAssemblies());

                   //add_ExtraMethodsFile();									// restore previous mappings here

                   //register cacheAssmbly
                   var codeMd5 = previousCompiledCodeText.md5Hash();
                   CompileEngine.CachedCompiledAssemblies.add(codeMd5, this.csharpCompiler().compiledAssembly().Location);

                   executeButton.enabled(true);

                   if (ExecuteOnCompile)
                       execute();
               });
        }