<HEAD><TITLE>CodeSmith使用基础教程 二 — 语法、标签--向东博客</TITLE>
<META http-equiv=Content-Language content=zh-CN>
<META http-equiv=Content-Type content="text/html; charset=gb2312">
<META content=oblog name=generator>
<META content=meil,meil name=author>
<META content=CodeSmith使用基础教程 二 — 语法、标签 name=keyword>
<META content=关键字:CodeSmith 使用教程 来源:http://blog.livebaby.cn三 name=description><LINK title=RSS href="/blog/u/meil/rss2.xml" type=application/rss+xml rel=alternate><LINK href="CodeSmith使用基础教程 二 — 语法、标签--向东博客_files/OblogUserDefault4[1].css" type=text/css rel=stylesheet>
</head>
<BODY>
<LINK href="CodeSmith使用基础教程 二 — 语法、标签--向东博客_files/css[1].css" type=text/css rel=stylesheet><LINK href="CodeSmith使用基础教程 二 — 语法、标签--向东博客_files/SyntaxHighlighter[1].css" type=text/css rel=stylesheet></LINK>
<DIV id=Header><SPAN id=blogname>向东博客</SPAN><SPAN id=blogurl>http://www.livebaby.cn/blog/u/meil/index.html</SPAN> </DIV>
<DIV id=Container>
<DIV class=PageBody>
<DIV class=MainBody>
<DIV class=topic>CodeSmith使用基础教程 二 — 语法、标签</DIV>
<DIV class=loginfo>meil 发表于 - 2007-7-2 23:58:00</DIV>
<DIV class=logtext>
<TABLE class=logtext_table>
<TBODY>
<TR>
<TD>
<DIV id=979 align=center>关键字:<B>CodeSmith</B> <B>使用教程</B> 来源:http://blog.livebaby.cn</DIV><BR>
<DIV><SPAN style="FONT-SIZE: 10pt"><STRONG>三、约定</STRONG></SPAN></DIV>
<DIV><SPAN style="FONT-SIZE: 10pt"></SPAN> </DIV>
<DIV><SPAN style="FONT-SIZE: 10pt"> 这里写的东东都是从CodeSmith自带的帮助文档中FAQ里学到的东东<IMG src="CodeSmith使用基础教程 二 — 语法、标签--向东博客_files/emsmilep[1].gif" align=absMiddle border=0><BR> 1.如何在模板中添加注释<BR></SPAN><SPAN style="FONT-SIZE: 10pt"><SPAN style="FONT-SIZE: 10pt"><SPAN style="FONT-SIZE: 10pt"> CodeSmith:<BR> <%-- Comments --%><BR> VB.NET:<BR> <%-- 'Comments --%><BR> C#:<BR> <%-- // Comments --%><BR> <%-- /* Comments */ --%><BR><BR> 2.创建一个可以下拉选择的属性<BR> 首先定义一个枚举类型的变量,然后将属性的类型设置为枚举型<BR></DIV>
<DIV style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><SPAN style="COLOR: #008080"> 1</SPAN> <SPAN style="COLOR: #000000"><%</SPAN><SPAN style="COLOR: #000000">@ Property Name</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">CollectionType</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000"> Type</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">CollectionTypeEnum</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000"> Category</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">Collection</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000"> Description</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">Type of collection</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #000000">%></SPAN><SPAN style="COLOR: #000000"><BR></SPAN><SPAN style="COLOR: #008080"> 2</SPAN> <SPAN style="COLOR: #000000"><BR></SPAN><SPAN style="COLOR: #008080"> 3</SPAN> <SPAN style="COLOR: #000000"></SPAN><SPAN style="COLOR: #000000"><</SPAN><SPAN style="COLOR: #000000">script runat</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">tempate</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">></SPAN><SPAN style="COLOR: #000000"><BR></SPAN><SPAN style="COLOR: #008080"> 4</SPAN> <SPAN style="COLOR: #000000">public enum CollectionTypeEnum<BR></SPAN><SPAN style="COLOR: #008080"> 5</SPAN> <SPAN style="COLOR: #000000">{<BR></SPAN><SPAN style="COLOR: #008080"> 6</SPAN> <SPAN style="COLOR: #000000"> Vector,<BR></SPAN><SPAN style="COLOR: #008080"> 7</SPAN> <SPAN style="COLOR: #000000"> HashTable,<BR></SPAN><SPAN style="COLOR: #008080"> 8</SPAN> <SPAN style="COLOR: #000000"> SortedList<BR></SPAN><SPAN style="COLOR: #008080"> 9</SPAN> <SPAN style="COLOR: #000000">}<BR></SPAN><SPAN style="COLOR: #008080">10</SPAN> <SPAN style="COLOR: #000000"></SPAN><SPAN style="COLOR: #000000"></</SPAN><SPAN style="COLOR: #000000">script</SPAN><SPAN style="COLOR: #000000">></SPAN></DIV>
<P><BR> 3.解决ASP.NET中标签<%重复问题<BR> 先将ASP.NET中使用的这个重复标签写成<%%,避免在生成代码时由于是标签重复引起的编译错误或生成错误。<BR><BR> 4.如何声明一个常量<BR> </P>
<DIV style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><SPAN style="COLOR: #000000"><</SPAN><SPAN style="COLOR: #000000">script runat</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">template</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">></SPAN><SPAN style="COLOR: #000000"><BR>private const string MY_CONST </SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">example</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">; <BR></SPAN><SPAN style="COLOR: #000000"></</SPAN><SPAN style="COLOR: #000000">script</SPAN><SPAN style="COLOR: #000000">></SPAN></DIV>
<P><BR> 5.如何对模板进行调试<BR> 如果要调试一个模板,首先要在代码模板里进行声明,然后在你想要进行调试的地方用Debugger.Break()语句设置断点即可。<BR></P>
<DIV style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><SPAN style="COLOR: #000000"><%</SPAN><SPAN style="COLOR: #000000">@ CodeTemplate Language</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">C#</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000"> TargetLanguage</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">T-SQL</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000"> Description</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #0