Purpose of reflection:
(1) Use Assembly to define and load the Assembly, load the module in the assembly list, and locate the type in this Assembly and create instances of this type.
(2) Use the module to understand the Assembly containing the module and the classes in the module, and obtain all global methods or other specific non-Global methods defined on the module.
(3) Use constructorinfo to understand the name, parameters, access modifiers (such as pulic or private) and implementation details (such as abstract or virtual) of the constructorinfo.
(4) use methodinfo to understand the method name, return type, parameters, access modifiers (such as pulic or private), and implementation details (such as abstract or virtual.
(5) Use fiedinfo to learn the field name, access modifier (such as public or private), implementation details (such as static), and obtain or set the field value.
(6) Use eventinfo to learn about the event name, event handler data type, custom attributes, declaration type, and reflection type, and add or remove event handlers.
Call methods through reflection
Protected void page_load (Object sender, eventargs E)
{
System. reflection. Assembly ass = assembly. loadfrom (appdomain. currentdomain. basedirectory + "bin \\\ webapplication1.dll"); // load DLL
System. type T = ass. GetType ("webapplication1.mainpage"); // obtain the type
String name = typeof (mainpage). assemblyqualifiedname;
System. Type T1 = type. GetType (name );
System. Type T2 = typeof (mainpage );
Object o = system. activator. createinstance (t); // create an instance
System. reflection. methodinfo MI = T. getmethod ("runjs1"); // obtain the Method
Mi. Invoke (O, new object [] {This. Page, "alert ('test reflection method')"}); // CALL THE METHOD
System. reflection. methodinfo Mi1 = T. getmethod ("runjs ");
Mi1.invoke (T, new object [] {This. Page, "alert ('test reflection mechanism 1')"}); // CALL THE METHOD
}
References: Reflection http://www.studyofnet.com/news/520.html in C #
This article from the "study also leisure" blog, please be sure to keep this source http://studyofnet.blog.51cto.com/8142094/1529631