很难说它们对 Helper/Block 的含义是什么,因为 Visual Studio T4 将不同的段称为 Statement、Expression、BoilerPlate 和 ClassFeature IIRC。
在检查 Mono T4 的源代码时,我猜想 Block 指的是 Statements 和 Helpers 指的是 ClassFeatures。
T4 示例:
<# // This is a Statement #>
<#+ // This is a ClassFeature #>
确实,语句不能出现在 T4 中的 ClassFeatures 下面,但我认为这里发生的是 Visual Studio T4 对 ttinclude 文件进行“智能”合并。Mono T4 可能没有。
看看为什么要考虑这两个 T4 文件。
示例 T4.tt包括:
<# // 1. This is a Statement #>
<#+ // 1. This is a ClassFeature #>
示例 T4.tt
<# // 2. This is a Statement #>
<#+ // 2. This is a ClassFeature #>
<#@ include file="T4.ttinclude" #>
一个简单的 include 实现只会合并文件:
<# // 2. This is a Statement #>
<#+ // 2. This is a ClassFeature #>
<# // 1. This is a Statement #>
<#+ // 1. This is a ClassFeature #>
但这是一个非法的 T4 模板,所以 Visual Studio T4 所做的(据我所知)是将文件合并到这个是合法的:
<# // 1. This is a Statement #>
<# // 2. This is a Statement #>
<#+ // 1. This is a ClassFeature #>
<#+ // 2. This is a ClassFeature #>
因此,如果允许我猜测,Mono T4 使用简单的方法包含文件,但 SubSonic 模板是为 Visual Studio T4 设计的,它使用稍微更精细的包含策略。
如果这是您需要的原因
- 重构 SQLLite.ttinclude 或 Settings.ttinclude 以仅使用 ClassFeatures。这可能是一个重大的重构,因为在 .ttinclude 文件中包含语句非常方便。
- 重构 Mono T4 以执行类似于 Visual Studio T4 的操作
我担心的也不是好消息。
PS。在阅读 Mono 代码时,开发人员似乎考虑了这一点:
//TODO: are blocks permitted after helpers?
throw new ParserException ("Blocks are not permitted after helpers", seg.StartLocation);