我是一个 T4 新手,试图使用T4 Toolbox根据这个答案生成 F# 代码,但似乎类功能块不能与语句块混合。这是我的代码:
<#@ template language="C#" hostspecific="True" debug="True" #>
<#@ output extension="txt" #>
<#@ include file="T4Toolbox.tt" #>
<#
FSharpTemplate template = new FSharpTemplate();
template.Output.Project = @"..\Library1\Library1.fsproj";
template.Output.File = "Module2.fs";
template.Render();
#>
<#+
class FSharpTemplate: Template
{
public override string TransformText()
{
#>
module Module2
<# for (int i = 0; i < 10; i++) { #>
<#= i #>
<# } #>
<#+
return this.GenerationEnvironment.ToString();
}
}
#>
我得到这个错误:
声明不能出现在模板中的第一类特征之后。在第一类特征块之后只允许样板、表达式和其他类特征。
那么......我怎样才能重写模板来实现这一点?