[C #] C # learning notes-type reflection, late binding, process, object context

Source: Internet
Author: User
Tags domain hosting

C # learning notes-type reflection,Late StageBinding, process, and object context

Luo chaohui (http://www.cnblogs.com/kesalin)

C # And. Net advancedProgramDesign Reading Notes

 

Reflection (reflection)

1. The Assembly metadata can not only describe a set of internal types, but also describe any external types referenced by internal types.

2. Reflection is the process found by a runtime database. through reflection, we can use programming to display the same metadata information as ildasm.exe. Reflection is defined in the system. Reflection namespace, while the system. Type class defines a large number of interfaces used to check a type of metadata.

3. We can use the system. Object. GetType (), system. type. GetType () and typeof () operators to obtain type references.

Late binding, features

4. Late binding is a technology that creates a given type of instance and calls its members at runtime without knowing its existence during compilation. Late binding is very important for program scalability. The system. activator class is the key in the late binding process of. net. It only defines several member methods, most of which are related to. NET remote processing.

5. When the. NET Platform runs, we use the feature to embed more metadata into the assembly. In short, the feature is used for type, Member, assembly, or moduleCodeAnnotation .. The net feature extends the abstract class type of the system. attribute base class. We can derive a new type from this class to create custom features. Features can be used in code only through explicit reflection.

 

Process, application domain, and object context

6. A process carries a set of related. Net assembly, and the application domain (appdomain) is a logical subdivision of the process. An application domain is further subdivided into multiple context boundaries, which are used to group similar. Net objects. Using Context, CLR ensures proper control of objects with special runtime requirements.

7. The system. Diagnostics namespace defines many types that allow us to programmatically access processes and many diagnostic-related types, such as system transaction logs, performance counters, and processes.

8. On the. NET platform, the Assembly is not directly hosted in the process. The. Net executable program is hosted in a logical partition of the process. The term is called the appdomain ). It can be seen that a process can contain multiple application domains, and each application domain carries one. Net executable program. Compared with the traditional Win32 process, this has the following benefits: first, the application domain is a key feature of the. NET platform operating system independence. This type of logical partition abstracts the differences between different operating systems and loaded executable programs. Second, compared with a complete process, the CPU and memory usage of the application domain is much less. Therefore, the CLR Load And Unload application domains is much faster than the complete process. Third, the application domain provides deep isolation for the hosted applications. If an application domain in the process fails, the remaining application domains will be supported.

9. A single process can host multiple application domains, each of which is completely isolated from other application domains in the process (or other processes. Therefore, if you do not use the distributed programming protocol (WCF ), applications Running in an application domain cannot access any data in other application domains (both global variables and static fields ). The operating system process can only host the default application domain. When the process starts, the CLR automatically creates this specific application domain (the default application domain, CLR can create other application domains as needed. If necessary (majority.. Net), you can use system. the static method of the appdomain class creates application domains programmatically in a given process. This class is also used for low-level control over the application domains (such as loading or detaching application domains ).

10. The application domain is the logical partition of the process that hosts the. NET assembly. Similarly, the application domain can be further divided into multiple context boundaries (content boundary ). In fact, the. NET context provides a way for individual application domains to create a "specific home" for a given object ". Using Context, CLR can ensure that objects with special requirements are executed. It can intercept the method calls in and out of the context for proper and consistent processing. The interception layer runs CLR to adjust the current method call to meet the setting requirements of the given object context. For example, if you define a C # class that requires automatic thread security (using the [synchronization] feature), CLR will create "context synchronization" during the allocation ". Like the default application domain defined by a process, each application domain has a default context. This default context is used to combine. Net objects that have no specific or unique requirements on the context. If the CLR determines that a newly created object has special requirements, a new context boundary will be created in the application domain hosting it.

11. A. Net object that does not need to know the specific context is called a context flexible object. These objects can be accessed from any location in the application domain hosting them, and they have nothing to do with the runtime requirements of the objects. Objects that require context allocation are called context-bound objects. They must be derived from the system. contextboundobject base class. On the surface of this base class, these objects can only run normally in the created context. A context-sensitive type can be modified using the. NET feature of a specific type-the context feature (derived from the system. runtime. remoting. contexts. contextattribute base class ).

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.