Export (0) Print
Expand All

Expression Syntax (Domain-Specific Languages) 

You 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 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 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:



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


For more information, see Security of Text Templates.

See Also

Community Additions

© 2014 Microsoft