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.