
In Visual Studio, a text template is a mixture of text blocks and control logic that can generate a text file. The control logic is written as fragments of program code in Visual C# or Visual Basic. The generated file can be text of any kind, such as a Web page, or a resource file, or program source code in any language. Text templates can be used at run time to produce part of the output of an application. They can also be used for code generation, in which the templates help build part of the source code of an application.
Run-time text generation lets you use templates to define part of the output of your application. For example, you could use a template to define an HTML report. The template looks like the generated output, but contains fragments of program code at the points where the output can vary. Whenever you edit the template during development, the template is transformed to a class. This class is compiled as part of the application. The similarity of the template to the resulting output helps you avoid mistakes when you need to change it.
Code generation lets you use templates to generate part of your application's source code and other resources from a model. For example, your model could be a diagram that defines the flow of control through a series of user dialogs. Whenever you edit the model during development, the text templates generate part of the application code and configuration files from the diagram. When the users' needs change, it is easy to discuss and change the diagram because it focuses on the business requirement.
Note |
|---|
A model is a file that one or more text templates read. It can be any kind of file or database. It does not have to be a UML model or a Domain-Specific Language model. A benefit of using text templates is that you can design the model to focus on an important aspect of your application that you want to make easy to change. |
http://www.olegsych.com/2007/12/text-template-transformation-toolkit/
A free T4 Editor that adds syntax highlighting and IntelliSense to Visual Studio for T4 Text Templates is here:
http://t4-editor.tangible-engineering.com
A tutorial on how to generate from an UML Diagram with Text Templates can be found here:
http://www.olegsych.com/2007/12/text-template-transformation-toolkit/

- 4/15/2010
- Tim F. Fischer
