Reflection is a very useful feature in .net.
It can be summarized in one sentence: Based on assembly and metadata, it can be dynamic The ability to create instances of a certain type, call methods, and access object members.
When the object to be called cannot be determined at compile time, reflection has to be used.
The most common application scenarios are:
1, database switching based on factory mode.
2, ORM framework, because it faces a universal model, and all properties or methods are dynamically generated.
3. For a plug-in-based system, if you don’t know what the external plug-in is at all, it will definitely not be determined at compile time, so reflection will be used to load it.
Since reflection is based on assembly and metadata, it is necessary to explain what an assembly is and when metadata is.
Assembly: An assembly is a collection of all types, which generates PE files after compilation (such as executable files.exe and class library files.dll).
Metadata: Metadata is part of the assembly and mainly includes information such as name, version, language culture and public key tag.
The above is the detailed content of A very useful feature in .net - reflection. For more information, please follow other related articles on the PHP Chinese website!