Understanding the core concepts of code generation
The concepts of source code generation, generative programming, and metaprogramming have been around for a very long time. The central concept is to develop programs that use input parameters, metadata, or both to output code themselves.
Input parameters are self-explanatory to programmers, and metadata will be covered in the next section. Because this is a hands-on book, we will not include much theory behind these techniques. Instead, for context, we will cursorily consider that the Visual Studio project and item templates are basically code generators themselves. Likewise, if you are familiar with T4 templates (usually denoted by the file extension .tt
, and T4 stands for Text Template Transformation Toolkit), you know their entire purpose is to generate code. In fact, Visual Studio itself uses T4 templates behind the scenes to output code, as we will see shortly.
The important thing to understand here is that code generators...