CodeSmith:
<%-- Comments --%>
VB.NET:
<%-- 'Comments --%>
C#:
<%-- // Comments --%>
<%-- /* Comments */ --%>
2.建立一个能够下拉选择的属性
首先定义一个枚举类型的变量,而后将属性的类型设置为枚举型
1
<%
@ Property Name
=
"
CollectionType
"
Type
=
"
CollectionTypeEnum
"
Category
=
"
Collection
"
Description
=
"
Type of collection
"
%>
2
3
<
script runat
=
"
tempate
"
>
4
public enum CollectionTypeEnum
5
{
6
Vector,
7
HashTable,
8
SortedList
9
}
10
</
script
>
3.解决ASP.NET中标签<%重复问题
先将ASP.NET中使用的这个重复标签写成<%%,避免在生成代码时因为是标签重复引发的编译错误或生成错误。
4.如何声明一个常量
<
script runat
=
"
template
"
>
private const string MY_CONST
=
"
example
"
;
</
script
>
5.如何对模板进行调试
若是要调试一个模板,首先要在代码模板里进行声明,而后在你想要进行调试的地方用Debugger.Break()语句设置断点便可。
<%
@ CodeTemplate Language
=
"
C#
"
TargetLanguage
=
"
T-SQL
"
Description
=
"
Debugging your template
"
Debug
=
"
true
"
%>
<%
Debugger.Break();
%>
6.如何将属性设置成选择一个文件夹的路径
[Editor(
typeof
(System.Windows.Forms.Design.FolderNameEditor),
typeof
(System.Drawing.Design.UITypeEditor))]
public
string
OutputDirectory
{
get
{
return
_outputDirectory;}
set
{_outputDirectory
=
value;}}