CodeSmith使用心得

Thumbnail

CodeSmith是一款著名的代码生成器,可以帮助开发者完成一些重复性的劳动,并且能够保证更高的代码质量。CodeSmith使用Template(*.cst )模板进行基础代码片段的定义,支持语言包括C#, Java, VB, PHP, ASP.NET, SQL等等。 一个简单的Sample CodeSmith使用的模板使用方式类似于aspx/jsp页面,也就是基础代码+脚本的方式,大致代码如下(官方的sample2)。 <%@ CodeTemplate Language="C#" TargetLanguage="Text" Description="This template demonstrates using properties in your template." %> <%@ Property Name="Person" Type="System.String" Description="This will show up at the bottom of the property grid when the property is selected." %> <%-- This template demonstrates using properties in your template. --%> This is some static content (just like the static HTML in a ASP page). <%= "Hello " + this.Person + "!" %> This is more static content. 这个结构熟悉吧,几行代码分别表示模板属性,参数,脚本(注释),脚本(输出),静态文本。 ...

2011-02-26 · alswl