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 #>
注意
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
Debugging
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
Concepts
How to: Add an Expression to Text Templates
Using Built-in Directives in Text Templates