Dynamic Generation of Code
Up to this point, the reflection services have been used to read type information at runtime. It is also possible to have your code build code. Dynamically building and running code is used in a number of different places throughout the .NET Framework. Two such examples are the Regex (regular expression) class and the XmlSerializer class. The tools are available for you to generate your own code by using code.
This section first discusses a simple “Hello World!” sample in which a single function can generate code for all of the languages supported. This function builds a code tree and then hands the tree over to the code generation APIs. This section will then delve into a more real-world sample where you gain improvement ...
Get .NET Common Language Runtime Unleashed now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.