[Reflection] 1

Source: Internet
Author: User

My understanding
Assembly: The. dll. EXE file.
Metadata: Class, enumeration, and so on in the Assembly.

I. Create a class library with vs2005
Using system;
Using system. Collections. Generic;
Using system. text;

Namespace classlibrary1
{
Public class class1
{

}

Public class class2
{

}

Public class class3
{

}
}
Generate classlibrary1.dll after compilation

Ii. Create a vs2005 Project
Using system;
Using system. Data;
Using system. configuration;
Using system. Web;
Using system. Web. Security;
Using system. Web. UI;
Using system. Web. UI. webcontrols;
Using system. Web. UI. webcontrols. webparts;
Using system. Web. UI. htmlcontrols;
Using system. reflection;

Public partial class _ default: system. Web. UI. Page
{
Protected void page_load (Object sender, eventargs E)
{

}

Protected void button#click (Object sender, eventargs E)
{
String strpath = @ "G: \ classlibrary1.dll ";
Assembly myassembly = assembly. loadfrom (strpath );
Type [] mytypes = myassembly. gettypes ();
Foreach (type mytype in mytypes)
{
If (mytype. isclass)
{
Label1.text + = mytype. Name + "<br/> ";
}
}
}
}

Iii. effect:
Click the button.
Class1
Class2
Class3

Iv. Summary
So far, we have successfully loaded an assembly, iterated in its contained types, and displayed the names of all classes in the Assembly.
Here we have demonstrated the most basic ideas for dealing with metadata in the Assembly Using Reflection. The rest of this article will show you how to do more things in the reflection class.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.