Simple Application of Text Template (. tt) in C #

Source: Internet
Author: User

In the past two days, the project encountered the. tt file, which has never been used before. So queries and takes notes to help you remember and later.

Click Select Text Template in add Project

 

The following code is pasted and a simple comment is made.

<# @ Template DEBUG = "false" hostspecific = "false" Language = "C #" #>< # @ Assembly name = "system. core "#> <# @ import namespace =" system. LINQ "#> <# @ import namespace =" system. text "#> <# @ import namespace =" system. collections. generic "#> <# @ output extension = ". CS "#> // format of the generated file. The file name is the same as the template name in this document. // body <# var user_obj = new string [] {" name "," Age ", "education" };#> class autocreate {<# For (INT I = 0; I <user_obj.length; I ++) {#> public static string <#= user_obj [I] #>;#}#>}
Observe that <###> this output format and Asp.net write on the page is a mode. the context in <# context #> is directly run by the compiler, while content outside of <# context #> is directly output as text.

After Ctrl + S is saved, the CS file is automatically generated, which is very powerful!

 

The end

 

Simple Application of Text Template (. tt) in C #

Related Article

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.