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.