Expression Syntax (Domain-Specific Languages)

You can use expression blocks in text templates to add strings to the generated text output. Expression blocks contain code that is first added to the generated transformation class with calls to ToString() attached to them. The transformation process will also apply the template's culture to the generated string. Typically, expression blocks are embedded inside text blocks. They are designed to change some aspect of the generated output text to use calculated values from external data, such as model files.

In text templates, expression blocks are delineated by using opening (<#=) and closing (#>) text template tags. The general syntax is:

<#= ExpressionCode #>

Note

Expressions must be on a single line in Visual Basic templates. Expressions can be on multiple lines in Visual C# templates.

The following code sample shows an expression:

<#= operation.Name #>

The following code sample shows a statement that performs a calculation, and then shows an expression that adds the result as a string to the generated text output:

<#
    int result = 95 * 95;
#> 
<#= result #>

The result of the previous example in the generated text is:

9025

See Also

Tasks

How to: Add an Expression to Text Templates

Walkthrough: Creating and Running Text Templates

Other Resources

Adding Code to Text Templates

Using Built-in Directives in Text Templates

Generating Artifacts By Using Text Templates

Change History

Date

History

Reason

July 2008

Rewrote and refactored project.

Content bug fix.