Templates are created and edited with a convenient editor, which provides context-sensitive code completion, error check, syntax highlighting and other features to speed up your work. All error and warning messages reported for errors in syntax of control code (not template compile-time errors) are automatically displayed in the Error List window. The Error List displays an error or warning message and the error location. You can easily navigate to the line that caused the error by double-clicking the error in the Error List window. Thus you may find and fix template errors quickly and conveniently.
Template language is T4-like and can be used to generate custom output from the Entity Developer model.
A text block is any non-programmatic text in a template. It can be added to a template by simply typing the text in it. Text blocks are passed to the output without changes.
|
Statement blocks are used to control the flow of processing in the text template. A statement block must be surrounded with '<#' and '#>' template tags (without quotes). In the statement blocks, you may use C# or Visual Basic statements to output things conditionally or to iterate over data to output things repeatedly for each item in that data. Statement language is determined by the template directive. Here is an example of the template with the template directive, statement blocks and a text block. <#@ template language="C#" #> The template output will be the following: Some text.
|
Expression blocks can be used to add an expression value, converted to a string, to the generated code. Usually expression blocks are used inside text blocks to place calculated values from external data (for example, model data) to the generated code. The expression in the expression block is calculated, converted to a string, and then placed to output. Expression blocks must be surrounded with '<#=' and '#>' template tags (without quotes). Here is an example of using an expression block. <#@ template language="C#" #> The template output will be the following: Some text 1.
|
Class feature blocks allow adding custom functions and fields to avoid repeating common code. You may call these functions inside the statement blocks and use fields in the expression blocks. A class feature block must be surrounded with '<#+' and '#>' template tags (without quotes). You may use expression and text blocks with the class feature block functions. Here is an example of using a class feature block. <#@ template language="C#"#> The template output will be the following: Some text.
|
Template directives are used to specify the language, whose syntax will be used when processing the statement, expression, and class feature blocks. Allowed values for the language parameter are "C#" or "VB". A template directive starts with the '<#@' directive opening tag, which is followed by the 'template' keyword, and the directive is closed with the '#>' closing tag. Then the language parameter is set. See the previous examples to learn how to use template directives.
|
Assembly directives are used to reference external assemblies, in order to use types within those assemblies from code in the text template. They have the name parameter, which must be set to a rooted file path or an assembly name. Here is an example of an assembly directive. <#@ assembly name="System.Data" #>
|
Import directives enable the use of specified namespace identifiers without providing a fully qualified name in a text template. They have the namespace parameter which must be set to the namespace for import. Here is an example of an assembly directive. <#@ import namespace="System.Collections" #>
|
Include directives are used for including templates, i.e. when in your template you want to use functions implemented in another template. So you can create a template file, implement a frequently used function in it, and by means of referring to this file from other templates, use this function. <#@ include file="Validation.tmpl" #>
|
Property directives are used to declare properties of the template. Here is an example of a property directive. <#@ property name="Output" category="Output" type="OutputInfo" editor="OutputInfoEditor" The property directive can have the following parameters:
|
Extended property directives are used to declare extended properties of model objects. Here is an example of an extended property directive. <#@ extended name="GenerateDataContractAttribute" owner="Class" type="System.Boolean" default="True" The extended property directive can have the following parameters:
|