VC # .NET entry classic ------ (special technical understanding) reflection article

xiaoxiao2021-03-06  118

I have always wondered what is the reflection in .NET. But after reading the following story, I want to have it necessary to write it yourself. I have a sharing, the original article is unknown, may be from MSDN.

What is reflection? Reflection, Chinese translation into reflection. This is the way to get runtime type information in .NET, .NET's application consists of several parts: 'assembly (askEMBLY)', 'module (module)', the reflection provides one Methods of programming allow programmers to get information about these components in the program running period, for example:

The Assembly class can get the running assembly information, or dynamically load the assembly, and find the type information in the assembly and create an instance of this type. The Type class can get the type of object of the object, this information contains all the features of the object: method, constructor, attribute, etc., information, etc., can be obtained by Type class, and call it. MethodInfo contains information about the method, and the name, parameter, return value, etc. of the method can be obtained, and can be called. Such, as well as FieldInfo, EventInfo, etc., all of which are included under System.Reflection namespace.

Relationship between naming space and assembly? Many people may still be very unclear about this concept, and it is necessary to clarify this point for qualified .NET programmers. The namespace is similar to the Java package, but it is not completely equivalent, because Java packs must be placed according to the directory structure, and the namespace does not need.

The assembly is the minimum unit of the .NET application, compiled .dll, .exe is a fitting.

The relationship between the accessories and namespace is not one or one, nor does it contain each other, and one of the fittings can have multiple namespaces, and a namespace can also exist in multiple assemblies, which may be a bit blurred. : Accessories A: Namespace n1 {public class ac1 {...} public class ac2 {...}} namespace n2 {public class ac3 {...} public class ac4 {...}} installed accessories B: Namespace n1 {public class bc1 {...} Public Class BC2 {...}} namespace n2 {public class bc3 {...} public class bc4 {...}}

There are two namespaces of N1 and N2 in these two assemblies, and each declare two classes, which is complete, then we reference the accessories A in an application, then in this app, we It can be seen that the classes below the N1 are AC1 and AC2, N2, and the classes below are AC3 and AC4. Then we remove the reference to A, plus the reference to B, then we can see the following classes under this application to become BC1 and BC2, N2 below. If we simultaneously quote these two assemblies, then we can see four classes: AC1, AC2, BC1 and BC2.

Here, we can clear a concept, named space just explaining that a type is that family, such as someone is a Han nationality; someone is a Hui; the assembly indicates where a type lives, such as someone living in Beijing, some people live in Shanghai Then there is a Han people in Beijing, and there are Hui people. There are Han people in Shanghai, and there are also Hui people. This is not contradictory.

转载请注明原文地址:https://www.9cbs.com/read-126185.html

New Post(0)