Click to Rate and Give Feedback
MSDN
MSDN Library
Visual Studio 2005
Visual Studio
Visual Studio SDK
 How to: Add a Statement to Text Tem...
This page is specific to
Microsoft Visual Studio 2005/.NET Framework 2.0

Other versions are also available for the following:
Domain-Specific Language Tools 
How to: Add a Statement to Text Templates 

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 using the language that is declared in the language parameter of the template directive.

To add a statement to a text template

  1. In Solution Explorer, right-click the text template file that you want to edit, and then click Open.

    The template opens in the editor.

  2. In text templates, you delineate code statements using an opening "<#" tag and a closing "#>" tag. 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:

    C#
    <<b>#</b>
       foreach(ModelType type in this.ClassModel.Types)
       {
    <b>#</b>>
            // templateblocks
    
    <<b>#</b>
       }
    <b>#</b>>
    

    Visual Basic
    <<b>#</b>
       Dim type as ModelType
       For Each type in Me.ClassModel.Types
    <b>#></b>
            // template blocks
    
    <b><#</b>
       Next
    <b>#></b>
    

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

NoteNote

To debug text templates, you must set the debug parameter of the template directive. For more information, see How to: Debug Text Templates.

Security

For more information, see Security of Text Templates.

See Also

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2008 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker