This documentation is archived and is not being maintained.

How to: Add a Statement to Text Templates

Visual Studio 2008

Updated: July 2008

You can use text templates to generate code, XML, reports, or other artifacts from models. You can use Statement Syntax blocks to add Visual Basic or Visual C# code to your template. The code should be expressed by using the language that is declared in the language parameter of the template directive.

To add a statement to a text template

  • In text templates, use an opening "<#" tag and a closing "#>" tag to delineate code statements. Add statement tags to your text template with code, as shown in the following example.

    In this example, the code loops through each ModelType in ClassModel.Types.

       foreach(ModelType type in this.ClassModel.Types)
            // templateblocks

       Dim type as ModelType
       For Each type in Me.ClassModel.Types
            // template blocks

For an example about how to create a fully coded and running text template, see Walkthrough: Creating and Running Text Templates




July 2008

Rewrote and refactored project.

Content bug fix.