Advertisement
Guest User

Untitled

a guest
Nov 21st, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.36 KB | None | 0 0
  1. #include <windows.h>
  2.  
  3. using namespace System;
  4. using namespace System::Windows;
  5. using namespace System::IO;
  6. using namespace System::Windows::Markup;
  7. using namespace System::Windows::Controls;
  8. using namespace System::CodeDom;
  9. using namespace System::CodeDom::Compiler;
  10. using namespace System::Reflection;
  11. using namespace System::Windows::Documents;
  12.  
  13.  
  14. public ref class MyApplication : public Application
  15. {
  16. public:
  17.  
  18. private: TextRange ^textRang;
  19. private: String ^program_begin, ^program_end, ^kod, ^tekst, ^st;
  20. private: Button ^addBtn, ^invokeBtn, ^setBtn;
  21. private: RichTextBox ^codeRTB;
  22. private: ListBox ^errorsListBox, ^methodsListBox, ^variablesListBox;
  23. private: Assembly^ modul;
  24. private: Type^ t;
  25. private: Object^ obj;
  26. private: array<MethodInfo^>^ methods;
  27. private: array<FieldInfo^>^ fields;
  28.  
  29. public: MyApplication(Window ^win)
  30. {
  31.  
  32. program_begin = gcnew String("Imports System" + Environment::NewLine + "Namespace test" + Environment::NewLine + "Public Class A" + Environment::NewLine);
  33. program_end = gcnew String(Environment::NewLine + "End Class" + Environment::NewLine + "End Namespace");
  34. kod = gcnew String("");
  35.  
  36.  
  37. addBtn = (Button^)win->FindName("addButton");
  38. addBtn->Click += gcnew RoutedEventHandler(this, &MyApplication::OnAddBtnClick);
  39. methodsListBox = (ListBox^)win->FindName("methodsListBox");
  40. methodsListBox->SelectionChanged += gcnew System::Windows::Controls::SelectionChangedEventHandler(this, &MyApplication::OnSelectionMethodsListBoxChanged);
  41. codeRTB = (RichTextBox^)win->FindName("codeRichTextBox");
  42. errorsListBox = (ListBox^)win->FindName("errorsListBox");
  43. methodsListBox = (ListBox^)win->FindName("methodsListBox");
  44. variablesListBox = (ListBox^)win->FindName("variablesListBox");
  45. }
  46.  
  47. private: System::Void OnSelectionMethodsListBoxChanged(Object^ sender, SelectionChangedEventArgs^ e)
  48. {
  49. // Add your code here
  50. }
  51.  
  52. private: System::Void OnAddBtnClick(Object^ sender, RoutedEventArgs^ e)
  53. {
  54. textRang = gcnew TextRange(codeRTB->Document->ContentStart, codeRTB->Document->ContentEnd);
  55. tekst = textRang->Text;
  56. String^ nowy_kod = gcnew String(program_begin + kod + "\n" + tekst + program_end);
  57. CodeDomProvider^ prov = CodeDomProvider::CreateProvider("VisualBasic");
  58. CompilerParameters^ param = gcnew CompilerParameters();
  59. param->GenerateInMemory = true;
  60. CodeSnippetCompileUnit^ csu = gcnew CodeSnippetCompileUnit(nowy_kod);
  61. CompilerResults^ res = prov->CompileAssemblyFromDom(param, csu);
  62.  
  63. if (res->Errors->Count > 0)
  64. {
  65. for (int i = 0; i<res->Errors->Count; i++)
  66. {
  67. errorsListBox->Items->Add(
  68. "Line number " + res->Errors[i]->Line +
  69. ", Error Number: " + res->Errors[i]->ErrorNumber +
  70. ", '" + res->Errors[i]->ErrorText + ";\n"
  71. );
  72. }
  73. }
  74. else {
  75. for (int i = 0; i < res->CompiledAssembly->GetType("Test.A")->GetMethods()->Length; i++) {
  76. methodsListBox->Items->Add(res->CompiledAssembly->GetType()->GetMethods()[i]->Name);
  77. }
  78. for (int i = 0; i < res->CompiledAssembly->GetType("Test.A")->GetFields()->Length; i++) {
  79. variablesListBox->Items->Add(res->CompiledAssembly->GetType()->GetFields()[i]->Name);
  80. }
  81. }
  82. }
  83.  
  84. };
  85.  
  86. [STAThread]
  87. int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
  88. LPSTR lpCmd, int nCmd)
  89. {
  90. Stream^ st = File::OpenRead("MainWindow.xaml");
  91. Window^ win = (Window^)XamlReader::Load(st, nullptr);
  92. Application^ app = gcnew MyApplication(win);
  93. app->Run(win);
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement