用 CodeSmith 生成可变化的代码,其实是先利用 CodeSmith 生成一个基类,然后自定义其它类继承于该类。当我们重新生成基类时 CodeSmith 不要接触继承的子类中的代码。看下面的这段模版脚本: % @CodeTemplateLanguage = " C# " TargetLanguage = " C# " Desc
用 CodeSmith 生成可变化的代码,其实是先利用 CodeSmith 生成一个基类,然后自定义其它类继承于该类。当我们重新生成基类时 CodeSmith 不要接触继承的子类中的代码。看下面的这段模版脚本: @ 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 %>
}
}