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 #