C # Discovery Tour 12th a fast ORM framework based on reflection and dynamic compilation (top)

Source: Internet
Author: User
Tags generator reflection

Dynamic compilation Technology

The so-called dynamic compilation technology is the application at run time, the program automatically generate C # code, and then call. NET Framework, the C # program compiler generates a temporary assembly, and then loads the temporary assembly into the object module that is dynamically invoked in the application domain.

The code generator is called internally by dynamic compilation technology. We used to use code generators to generate code documents, then add them to the C # project, and then compile them as a whole, at which point we use code generators manually, which can be called static compilation. Dynamic compilation, however, automates this process, and the process of generating code text by invoking the code generator is placed at the time the software runs.

Dynamic compilation technology can combine flexibility and performance at the same time. Microsoft. NET Framework itself also has the application of dynamic compilation technology, such as XML serialization and deserialization, ASP. NET Framework handles ASPX files, and so on.

Generally speaking, the process of using dynamic compilation technology can be considered

1. The application needs to invoke the dynamic compilation feature, collect some parameters, and then invoke the dynamic compilation module.

2. The dynamic compilation module has a cached list of global, temporarily compiled assemblies that are returned directly to the Assembly object if a matching temporary assembly can be found in the cached list by parameters passed by the application.

3. Dynamically compile module collection parameters, and then call the built-in code generator to generate code strings.

4. Dynamic compilation module calls Microsoft. NET Framework, which generates a temporary assembly object for the C # code compiler. Specifically, the method that the Microsoft.CSharp.CSharpCodeProvider provides is invoked. In this process, the program will generate a number of temporary files on disk, the process will be Microsoft. The impact of the security settings of the NET Framework.

5. Save the generated assembly object temporarily to a cached list of global temporary assemblies, and then return the temporary assembly to the application, and the application will use reflection to invoke the functionality provided by the temporary assembly.

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.