Prior to being familiar with the basic concepts of reflection correlation, knowing how to get the assembly class and the type class, we then practiced through a small program and experienced a list of all types contained in a given *.dll or *.exe assembly through reflection dynamically (the list includes methods, fields, properties for a given type definition , events, supported interfaces, method parameters, base classes, namespaces, and so on).
Goal: Use WinForm to write a gadget that can view the metadata for a specified DLL.
The interface is as follows:
The controls used include:
button, OpenFileDialog dialog box, ComboBox (DropDownList type), TextBox (multiline is True)
The first step:
Gets the specified DLL file path, loads the DLL into memory based on the path, obtains the corresponding assembly (Assembly), and further obtains all the classes defined in the assembly, binding the string name of the class as the data source to the ComboBox
Step Two:
The Cbbdll_selectedindexchanged event is triggered when the ComboBox selection changes. Gets the corresponding type from the assembly according to the selected string name, passing the types to the ShowMessage method
Step Three:
Add a static class, add a method, get the information defined in the incoming type (methods, fields, properties, events, etc.)
Field:
Property:
Event:
Interface:
Method and its return value type, parameter type
Run:
Precautions:
Select External Application A.dll, if the A.dll references other assemblies (such as B.dll), the program should load B.dll into memory before loading a.dll into memory, otherwise it will report an exception.
Reflection Learning Notes (ii) Dynamically get class types and member types in external assemblies