Reflecting : Reflection Util « Reflection « Visual C++ .NET

Home
Visual C++ .NET
1.2D
2.Class
3.Collections
4.Data Type
5.Database ADO.net
6.Delegate
7.Development
8.File Directory
9.Function
10.Generics
11.GUI Form
12.Language Basics
13.Network
14.Reflection
15.Security
16.Statement
17.Structure
18.Thread
19.XML
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Visual C++ .NET » Reflection » Reflection Util 
Reflecting
 

  using namespace System;
  using namespace System::ComponentModel;
  using namespace System::Collections;
  using namespace System::Windows::Forms;
  using namespace System::Data;
  using namespace System::Drawing;
  using namespace System::Reflection;

  public ref class Form1 : public System::Windows::Forms::Form
  {
  public:
    Form1(void)
    {
      InitializeComponent();
    }

    System::Windows::Forms::Label^  label3;
    System::Windows::Forms::Label^  label4;
    System::Windows::Forms::Label^  label5;
    System::Windows::Forms::ListBox^  lbMethods;
    System::Windows::Forms::ListBox^  lbProperties;
    System::Windows::Forms::ListBox^  lbVariables;
    System::Windows::Forms::GroupBox^  groupBox1;
    System::Windows::Forms::ComboBox^  cbDataTypes;
    System::Windows::Forms::ComboBox^  cbAssemblies;
    System::Windows::Forms::Label^  label2;
    System::Windows::Forms::Label^  label1;

    array<Type^>^ types;
    static array<String^>^ assemblies =
             {
                 "System",
                 "System.Drawing",
                 "System.Xml",
                 "System.Windows.Forms",
                 "System.Data",
                 "mscorlib"
             };

    System::ComponentModel::Container ^components;

    void InitializeComponent(void)
    {
      this->label3 = (gcnew System::Windows::Forms::Label());
      this->label4 = (gcnew System::Windows::Forms::Label());
      this->label5 = (gcnew System::Windows::Forms::Label());
      this->lbMethods = (gcnew System::Windows::Forms::ListBox());
      this->lbProperties = (gcnew System::Windows::Forms::ListBox());
      this->lbVariables = (gcnew System::Windows::Forms::ListBox());
      this->groupBox1 = (gcnew System::Windows::Forms::GroupBox());
      this->cbDataTypes = (gcnew System::Windows::Forms::ComboBox());
      this->cbAssemblies = (gcnew System::Windows::Forms::ComboBox());
      this->label2 = (gcnew System::Windows::Forms::Label());
      this->label1 = (gcnew System::Windows::Forms::Label());
      this->groupBox1->SuspendLayout();
      this->SuspendLayout();
      // 
      // label3
      // 
      this->label3->AutoSize = true;
      this->label3->Location = System::Drawing::Point(1594);
      this->label3->Name = L"label3";
      this->label3->Size = System::Drawing::Size(5113);
      this->label3->TabIndex = 11;
      this->label3->Text = L"Methods:";
      // 
      // label4
      // 
      this->label4->AutoSize = true;
      this->label4->Location = System::Drawing::Point(32094);
      this->label4->Name = L"label4";
      this->label4->Size = System::Drawing::Size(5713);
      this->label4->TabIndex = 12;
      this->label4->Text = L"Properties:";
      // 
      // label5
      // 
      this->label5->AutoSize = true;
      this->label5->Location = System::Drawing::Point(58594);
      this->label5->Name = L"label5";
      this->label5->Size = System::Drawing::Size(5313);
      this->label5->TabIndex = 13;
      this->label5->Text = L"Variables:";
      // 
      // lbMethods
      // 
      this->lbMethods->FormattingEnabled = true;
      this->lbMethods->Location = System::Drawing::Point(15114);
      this->lbMethods->Name = L"lbMethods";
      this->lbMethods->Size = System::Drawing::Size(293251);
      this->lbMethods->TabIndex = 14;
      // 
      // lbProperties
      // 
      this->lbProperties->FormattingEnabled = true;
      this->lbProperties->Location = System::Drawing::Point(320114);
      this->lbProperties->Name = L"lbProperties";
      this->lbProperties->Size = System::Drawing::Size(250251);
      this->lbProperties->TabIndex = 15;
      // 
      // lbVariables
      // 
      this->lbVariables->FormattingEnabled = true;
      this->lbVariables->Location = System::Drawing::Point(585114);
      this->lbVariables->Name = L"lbVariables";
      this->lbVariables->Size = System::Drawing::Size(202251);
      this->lbVariables->TabIndex = 16;
      // 
      // groupBox1
      // 
      this->groupBox1->Controls->Add(this->cbDataTypes);
      this->groupBox1->Controls->Add(this->cbAssemblies);
      this->groupBox1->Controls->Add(this->label2);
      this->groupBox1->Controls->Add(this->label1);
      this->groupBox1->Location = System::Drawing::Point(1412);
      this->groupBox1->Name = L"groupBox1";
      this->groupBox1->Size = System::Drawing::Size(44372);
      this->groupBox1->TabIndex = 10;
      this->groupBox1->TabStop = false;
      // 
      // cbDataTypes
      // 
      this->cbDataTypes->FormattingEnabled = true;
      this->cbDataTypes->Location = System::Drawing::Point(12041);
      this->cbDataTypes->Name = L"cbDataTypes";
      this->cbDataTypes->Size = System::Drawing::Size(28721);
      this->cbDataTypes->TabIndex = 3;
      this->cbDataTypes->SelectedIndexChanged += gcnew System::EventHandler(this, &Form1::cbDataTypes_SelectedIndexChanged);
      // 
      // cbAssemblies
      // 
      this->cbAssemblies->FormattingEnabled = true;
      this->cbAssemblies->Location = System::Drawing::Point(12016);
      this->cbAssemblies->Name = L"cbAssemblies";
      this->cbAssemblies->Size = System::Drawing::Size(28721);
      this->cbAssemblies->TabIndex = 2;
      this->cbAssemblies->SelectedIndexChanged += gcnew System::EventHandler(this, &Form1::cbAssemblies_SelectedIndexChanged);
      // 
      // label2
      // 
      this->label2->AutoSize = true;
      this->label2->Location = System::Drawing::Point(2444);
      this->label2->Name = L"label2";
      this->label2->Size = System::Drawing::Size(8713);
      this->label2->TabIndex = 1;
      this->label2->Text = L"Select data type:";
      // 
      // label1
      // 
      this->label1->AutoSize = true;
      this->label1->Location = System::Drawing::Point(2419);
      this->label1->Name = L"label1";
      this->label1->Size = System::Drawing::Size(8613);
      this->label1->TabIndex = 0;
      this->label1->Text = L"Select assembly:";
      // 
      // Form1
      // 
      this->AutoScaleDimensions = System::Drawing::SizeF(613);
      this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
      this->ClientSize = System::Drawing::Size(801377);
      this->Controls->Add(this->label3);
      this->Controls->Add(this->label4);
      this->Controls->Add(this->label5);
      this->Controls->Add(this->lbMethods);
      this->Controls->Add(this->lbProperties);
      this->Controls->Add(this->lbVariables);
      this->Controls->Add(this->groupBox1);
      this->Name = L"Form1";
      this->Text = L"Assembly Viewer";
      this->Load += gcnew System::EventHandler(this, &Form1::Form1_Load);
      this->groupBox1->ResumeLayout(false);
      this->groupBox1->PerformLayout();
      this->ResumeLayout(false);
      this->PerformLayout();
    }
        System::Void Form1_Load(System::Object^ sender, System::EventArgs^  e)
        {

            for each (String ^assembly  in assemblies)
            {
                cbAssemblies->Items->Add(assembly);
            }
            cbAssemblies->SelectedIndex = 0;
        }

        System::Void cbAssemblies_SelectedIndexChanged(System::Object^ sender,
                                                       System::EventArgs^  e)
        {
            Assembly^ assembly = Assembly::LoadWithPartialName(
                                 assemblies[cbAssemblies->SelectedIndex]);

            types = assembly->GetTypes();

            cbDataTypes->Items->Clear();

            for (int i = 0; i < types->Length; i++)
            {
                cbDataTypes->Items->Add(types[i]->ToString());
            }
            cbDataTypes->SelectedIndex = 0;
        }

        System::Void cbDataTypes_SelectedIndexChanged(System::Object^ sender,
                                                      System::EventArgs^  e)
        {
            Type ^type = types[cbDataTypes->SelectedIndex];

            array <MemberInfo^>^ methods = type->GetMethods();
            lbMethods->Items->Clear();
            for (int i = 0; i < methods->Length; i++)
            {
                lbMethods->Items->Add(methods[i]->ToString());
            }

            array <PropertyInfo^>^ properties = type->GetProperties();
            lbProperties->Items->Clear();
            for (int i = 0; i < properties->Length; i++)
            {
                lbProperties->Items->Add(properties[i]->ToString());
            }

            array <MemberInfo^>^ variables = type->GetFields();
            lbVariables->Items->Clear();
            for (int i = 0; i < variables->Length; i++)
            {
                lbVariables->Items->Add(variables[i]->ToString());
            }
        }
    };

[STAThreadAttribute]
int main(array<System::String ^> ^args)
{
  Application::Run(gcnew Form1());
  return 0;
}

   
  
Related examples in the same category
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.