Click to Rate and Give Feedback
MSDN
MSDN Library
Visual Studio 2005
Visual Studio
Visual Studio SDK
 How to: Add an Expression to Text T...
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 an Expression to Text Templates 

You can use text templates to generate code, XML, reports, or other artifacts from models. A text template file contains a mixture of text blocks and control logic. The control logic is used to combine the text blocks with the data that a model holds to produce an output file.

You can use the Expression Syntax (Domain-Specific Languages) block to add a string that is generated in the culture that is specified in the culture parameter of the template directive. For more information, see How to: Specify a Culture in Text Templates.

To add an expression 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. In text templates, you delineate code expressions by using an opening "<#=" tag and a closing "#>" tag.

  2. Add the following expression to the template:

    C#
    <#
       foreach(ModelType type in this.ClassModel.Types)
       {
          if (type is ModelClass)
          {
    #>
             <b><#=</b> type.Name <b>#></b>
    <#
          }
       }
    #>
    

    Visual Basic
    <#
       Dim type as ModelType
       For Each type in Me.ClassModel.Types
          If TypeOf(type) Is ModelClass Then
    #>
             <b><#=</b> type.Name <b>#></b>
    <#
          End If
       Next
    #>
    

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