Supplement of reflection
Load the Assembly and obtain various items
The code is very clear.
Using System;
Using System. Collections. Generic;
Using System. Text;
Using System. Reflection;
Namespace FanShe
{
Public class Test
{
Assembly myAssembly = null;
Public Test ()
{
// Method 1:
// MyAssembly = Assembly. LoadFrom (@ "E: \ study \ TestDemo \ FanShe \ bin \ Debug \ FanShe.exe"); // path
// Method 2
MyAssembly = Assembly. Load ("FanSheDll"); // note that the Assembly name is "FanSheDll" instead of "FanShe. Dll ".
}
Public void Start ()
{
Assembly [] assemblys = AppDomain. CurrentDomain. GetAssemblies (); // obtain all the current Assembly
Foreach (Assembly item in assemblys)
{
This. getreflectioninfo (item );
}
}
// Define a method to obtain the reflected content
Private void getreflectioninfo (Assembly myassembly)
{
Type [] typearr = myAssembly. GetTypes (); // obtain the Type
Foreach (Type type in typearr) // obtain detailed information for each Type
{
// Obtain the structure information of the type
ConstructorInfo [] myconstructors = type. GetConstructors ();
// Obtain the field information of the type.
FieldInfo [] myfields = type. GetFields ();
// Obtain method information
MethodInfo [] myMethodInfo = type. GetMethods ();
// Obtain the Property Information
PropertyInfo [] myproperties = type. GetProperties ();
// Obtain event information
EventInfo [] Myevents = type. GetEvents ();
}
}
}
}