Dynamic soft code generator--Template development Learning

Source: Internet
Author: User

Today saw the soft online help, now the template development Tutorial section written out, in order to facilitate future inquiries, hope can also help others. The article just copied the online Help, adjusted the format.

The template is broadly divided into 5 parts:
    • Template instruction Block declaration
    • Code statement block
    • Expression block
    • class function control block
    • Text block output

Each section is explained below:

Template instruction Block declaration

As with the instructions for an ASP. NET page, they appear in the file header, represented by <#@...#>.

1. Template directives

As <#@ template ...#>, it is a necessary part to define the basic properties of a template.

Instruction format:

<#@ template [language="VB"] [hostspecific="true"] [debug ="true"] [inherits="templatebaseclass"] [culture=  "code"[compileroptions="options"] #>

Language: This allows you to specify the language used by the template.

Hostspecific= "True" indicates whether the use of a specific host,host contains the various objects used by the template.

For example:

<#@ template language="C #" hostspecific="True" #>

Note :

All attribute values must be enclosed in double quotation marks. If the value itself contains quotation marks, these quotes must be escaped with the \ character. A directive is usually the first element in a template file or contained file.

2. Parameter directives

With <#@ Patameter ...#> said

Instruction format:

<#@ parameter type="full.typename" name= "parametername " #>

3. Output instructions

expressed as <#@ output ...#>

Instruction format:

<#@ output extension=". Filenameextension"  encoding="encoding "  #>

extension= ". cs" Specifies the extension of the build file.

encoding= "Encoding" specifies the encoding of the generated file.

4. Assembly Directives

as <#@ assembly ...#> , to add an assembly reference, if you want to use a third-party assembly, it is a good idea to add a reference to the project.

For example:

<#@ Assembly name="system.data" #>

Note: You should use the name of the absolute path, or use the name of the standard macro in the path name.

For example:

<#@ Assembly name="$ (solutiondir) Library\myassembly.dll" #>

5. Import Instructions

in <#@ import ...#> , import the namespaces that you want to use.

Attention:

The namespaces here must be found in the previously specified assembly, such as I specify the namespace "System.Data", "System.Data.Common", which are available in the assembly System.Data.

For example:

namespace="system.data" #>

6. include Directives

in <#@ include ...#> , an import template, similar to an include usage of HTML, inserts the text of other template files into the include directive.

For example:

<#@ include file="test.tt" #>

<#@ include file= "C:\test.txt" #>

When processed, the content is included as if it were part of a text template. However, even if the include directive is followed by plain text blocks and standard control blocks, you can also include files that write class function blocks <#+...#>. Code statement block

Dynamic soft code generator--Template development Learning

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.