标签:http io ar os for sp 文件 div on
这两天做项目突遇 .tt文件,之前没有接触过,so查询学习做笔记,帮助记忆和后来者。
在项目添加中点击选择文本模板

下面贴出代码,做了简单的注释
01.<#@ template debug="false" hostspecific="false" language="C#" #>02.<#@ assembly name="System.Core" #>03.<#@ import namespace="System.Linq" #>04.<#@ import namespace="System.Text" #>05.<#@ import namespace="System.Collections.Generic" #>06.<#@ output extension=".cs" #> //生成的文件格式,文件名称同文本模板名称相同07. 08.//正文09.<# var user_obj = new string [] {"Name", "Age", "Education"}; #>10.class AutoCreate11.{12.<# for(int i= 0; i< user_obj.Length ; i ++){ #>13.public static string <#= user_obj[i] #>;14.<# }#>15.}1.观察一下<#= #>这种输出格式和asp.net在页面上输出时写<%= %>是一个模式.2.<# context #>中的context就被编译器直接运行,而<# context #>之外的内容当做文本直接输出<br><br>Ctrl+S保存后,自动生成cs文件,很好很强大!

THE END
标签:http io ar os for sp 文件 div on
原文地址:http://www.cnblogs.com/victor-wxy/p/4077930.html