void CompileAndRun(object sender, RoutedEventArgs e) { Snippet snippet = new Snippet(codeBox.Text, CurrentOptions); CompilerResults results = snippet.Compile(); output.Inlines.Clear(); foreach (CompilerError error in results.Errors) { Run run = new Run("Line " + error.Line + ": " + error.ErrorText); run.Foreground = error.IsWarning ? Brushes.MediumBlue : Brushes.Red; output.Inlines.Add(run); output.Inlines.Add(new LineBreak()); } if (results.Errors.HasErrors) { Run run = new Run("(Build failed)"); run.Foreground = Brushes.Red; output.Inlines.Add(run); return; } else { Run run = new Run("(Build successful)"); run.Foreground = Brushes.MediumBlue; output.Inlines.Add(run); output.Inlines.Add(new LineBreak()); Type snippetType = results.CompiledAssembly.GetType("Snippet"); try { snippetType.GetMethod("Main").Invoke(null, new object[] { new string[] { } }); } catch (TargetInvocationException ex) { Run error = new Run(string.Format("Exception: {0}", ex.InnerException)); error.Foreground = Brushes.Red; output.Inlines.Add(error); } } }