Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <windows.h>
- using namespace System;
- using namespace System::Windows;
- using namespace System::IO;
- using namespace System::Windows::Markup;
- using namespace System::Windows::Controls;
- using namespace System::CodeDom;
- using namespace System::CodeDom::Compiler;
- using namespace System::Reflection;
- using namespace System::Windows::Documents;
- public ref class MyApplication : public Application
- {
- public:
- private: TextRange ^textRang;
- private: String ^program_begin, ^program_end, ^kod, ^tekst, ^st;
- private: Button ^addBtn, ^invokeBtn, ^setBtn;
- private: RichTextBox ^codeRTB;
- private: ListBox ^errorsListBox, ^methodsListBox, ^variablesListBox;
- private: Assembly^ modul;
- private: Type^ t;
- private: Object^ obj;
- private: array<MethodInfo^>^ methods;
- private: array<FieldInfo^>^ fields;
- public: MyApplication(Window ^win)
- {
- program_begin = gcnew String("Imports System" + Environment::NewLine + "Namespace test" + Environment::NewLine + "Public Class A" + Environment::NewLine);
- program_end = gcnew String(Environment::NewLine + "End Class" + Environment::NewLine + "End Namespace");
- kod = gcnew String("");
- addBtn = (Button^)win->FindName("addButton");
- addBtn->Click += gcnew RoutedEventHandler(this, &MyApplication::OnAddBtnClick);
- methodsListBox = (ListBox^)win->FindName("methodsListBox");
- methodsListBox->SelectionChanged += gcnew System::Windows::Controls::SelectionChangedEventHandler(this, &MyApplication::OnSelectionMethodsListBoxChanged);
- codeRTB = (RichTextBox^)win->FindName("codeRichTextBox");
- errorsListBox = (ListBox^)win->FindName("errorsListBox");
- methodsListBox = (ListBox^)win->FindName("methodsListBox");
- variablesListBox = (ListBox^)win->FindName("variablesListBox");
- }
- private: System::Void OnSelectionMethodsListBoxChanged(Object^ sender, SelectionChangedEventArgs^ e)
- {
- // Add your code here
- }
- private: System::Void OnAddBtnClick(Object^ sender, RoutedEventArgs^ e)
- {
- textRang = gcnew TextRange(codeRTB->Document->ContentStart, codeRTB->Document->ContentEnd);
- tekst = textRang->Text;
- String^ nowy_kod = gcnew String(program_begin + kod + "\n" + tekst + program_end);
- CodeDomProvider^ prov = CodeDomProvider::CreateProvider("VisualBasic");
- CompilerParameters^ param = gcnew CompilerParameters();
- param->GenerateInMemory = true;
- CodeSnippetCompileUnit^ csu = gcnew CodeSnippetCompileUnit(nowy_kod);
- CompilerResults^ res = prov->CompileAssemblyFromDom(param, csu);
- if (res->Errors->Count > 0)
- {
- for (int i = 0; i<res->Errors->Count; i++)
- {
- errorsListBox->Items->Add(
- "Line number " + res->Errors[i]->Line +
- ", Error Number: " + res->Errors[i]->ErrorNumber +
- ", '" + res->Errors[i]->ErrorText + ";\n"
- );
- }
- }
- else {
- for (int i = 0; i < res->CompiledAssembly->GetType("Test.A")->GetMethods()->Length; i++) {
- methodsListBox->Items->Add(res->CompiledAssembly->GetType()->GetMethods()[i]->Name);
- }
- for (int i = 0; i < res->CompiledAssembly->GetType("Test.A")->GetFields()->Length; i++) {
- variablesListBox->Items->Add(res->CompiledAssembly->GetType()->GetFields()[i]->Name);
- }
- }
- }
- };
- [STAThread]
- int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
- LPSTR lpCmd, int nCmd)
- {
- Stream^ st = File::OpenRead("MainWindow.xaml");
- Window^ win = (Window^)XamlReader::Load(st, nullptr);
- Application^ app = gcnew MyApplication(win);
- app->Run(win);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement