[C #] C # learning notes-pencil and dynamic assembly

Source: Internet
Author: User

C # learning notes-pencil and DynamicsProgramSet

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

Book notes on C # And. Net Advanced Programming

 

1, system. reflection. the emit namespace provides many features that can be generated in the memory during runtime. net assembly type. The formal term for defining and executing an assembly in memory is dynamic assembly ). We dynamically build an assembly using the proprietary pencil (Common intermediate language) instruction set.

2. the. NET platform is essentially the mother tongue of the. NET platform. When we choose a managedProgramming Language(C #, VB, COBOL. net, etc.) when constructing a. Net assembly, the compiler related to this language willSource codeTranslate it into a pencil. We can directly use the. NET Framework SDK to develop and build. Net assemblies using the. net sdk and cilcompilers (ilasm.exe), although we seldom do this. In this case, the. NET developer who maps the pencil to is like a C ++ programmer in the assembly language.

3. the pencil defines a set of common keywords. These keywords can be divided into three categories: the pencil command, the pencil feature, and the pencil operation code.
The pencil command is used to describe the overall structure of the. NET assembly. It is used to notify the pencil compiler how to define the namespace, type, and Members used in the assembly. A (.) prefix is used in the pencil command syntax, such as. namespace,. Class,. publickeytoken,. method,. assembly, and so on.
The pencil feature defines how to handle a pencil command. For example, A. Class command can be combined with the public feature (explicit class visibility), extends feature (definite class base class), and implements feature (clear class support interface.
The pencil operation code provides the class implementation logic. For example, ldstr (reprinted string), box, Unbox, throw, sizeof, etc.

4. A single stack-based development language. The virtual execution stack is used in the template to implement the stack. The process of pushing an operation code into this stack is called load, and the process of moving the operation code from the top of the stack to the memory (such as local variables) is called store ). It is not allowed to directly access a data, including local variables, variables or type field data passed in the method. To achieve access, you must explicitly load data to the stack and bring it up during use.

5. Positive and reverse engineering: You can use ildasm.exe to loadCodeExport to external files. You can use the cilcompiler ilasm.exe to re-compile the files with the cilcode. The positive and reverse engineering allows us to modify an assembly without source code, or supplement the loss of IDL features in the Assembly with COM interoperability.

6. dynamic assembly is running by using system. reflection. the types provided by the emit namespace are created in the memory. reflection. the emit namespace makes it possible to create an Assembly and its modules, define the types, and implement the logic of the template at runtime. Once this is done, the binary program in the memory can be saved to the disk to generate a new static assembly. Although it is not very common to create a dynamic assembly, this technology is very useful in the following scenarios: first, the build needs to generate the Assembly file based on user input. NET development tool; second, build a program that requires the remote proxy to be generated through metadata at runtime; third, you want to load the static assembly and dynamically Insert a new type to the binary image.

 

Related Article

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.