<%@ CodeTemplate Language="C#" TargetLanguage="C#" Description="Base class generator." %>
<%@ Property Name="ClassName" Type="System.String" Description="Name of the class." %>
<%@ Property Name="ConstructorParameterName" Type="System.String" Description="Constructor parameter name." %>
<%@ Property Name="ConstructorParameterType" Type="System.String" Description="Data type of the constructor parameter." %>
class <%= ClassName %>
{
<%= ConstructorParameterType %> m_<%= ConstructorParameterName %>;
public <%= ClassName %>(<%= ConstructorParameterType %> <%= ConstructorParameterName %>)
{
m_<%= ConstructorParameterName %> = <%= ConstructorParameterName %>
}
}执行该模版并输入如下数据:
该模版生成的代码可能如下:
1
class Account
2
{
3
int m_balance;
4
5
public Account(int balance)
6
{
7
m_balance = balance
8
}
9
10
}
11
12
class Account2
{3
int m_balance;4
5
public Account(int balance)6
{7
m_balance = balance8
}9

10
}11

12

把生成的文件保存为Account.cs文件。这时我们可以编写第二个类生成Check.cs文件代码:
1
class Checking : Account
2
{
3
public Checking : base(0)
4
{
5
}
6
}
class Checking : Account2
{3
public Checking : base(0)4
{5
}6
}现在如果需要改变Account Balance的类型为浮点型,我们只需要改变ConstructorParameterType属性为float,并重新生成Account.cs文件即可而不需要直接在Account.cs中进行手工修改,并且不需要修改Check.cs文件的任何代码。

