A very useful feature in .net - reflection

零下一度
Release: 2017-06-26 15:39:04
Original
1760 people have browsed it

Reflection is a very useful feature in .net.

What is reflection

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.

Why use reflection

When the object to be called cannot be determined at compile time, reflection has to be used.

Reflection application scenarios

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.

Assembly

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template