Reflection (1) Recognition reflection and reflection Recognition
Reflection is a very useful feature in. net.
What is reflection?
It can be summarized in one sentence as follows:Based on assembly and metadata, YesDynamicCreates an instance of a type, calls a method, and accesses an object member.
Why use reflection?
Reflection is required when the object to be called cannot be determined during compilation.
Application scenarios of reflection
The most common application scenarios are:
1. Database Switching Based on the factory mode.
2. ORM framework, because it faces common models, all attributes or methods are dynamically generated.
3. A plug-in-based system cannot be determined during the compilation period without knowing exactly what the external plug-in is. Therefore, reflection is used for loading.
Assembly
Because reflection is based on the Assembly and metadata, it is necessary to explain what is the assembly and when metadata.
Assembly: a program set is a collection of all workers. After compilation, a file (such as executable file .exe and class library file. dll) is generated ).
Metadata: metadata is a part of an assembly and mainly contains information such as name, version, language and culture, and public key tag.