c# - 尝试在 sharpdevelop 中执行 subsonic 的 activerecord 时出现 T4 模板生成错误

标签 c# sqlite activerecord t4 sharpdevelop

你好,
我正在尝试让亚音速在 sharpdevelop(事件记录方法)中赢得 SQLite。
我在从 T4 模板生成代码时遇到了一些问题。

它抛出这个错误: 助手后不允许有 block - SQLiteTest.tt

如果我删除 <#@ include file="SQLite.ttinclude" #>线 它不再抛出错误,但它当然不起作用。

错误必须在 SQLite.ttincludeSettings.ttinclude 中的某处 我查看了 ttinclude 文件,但我不知道 block 或助手是什么。

您是否知道错误的可能原因是什么? 显然,单声道开发 T4 生成器会抛出相同的错误,但 Visual Studio 的不会。

最佳答案

很难说出它们对 Helper/Block 的含义,因为 Visual Studio T4 将不同的部分称为 Statement、Expression、BoilerPlate 和 ClassFeature IIRC。

同时检查 source code然而,对于 Mono T4,我猜测 Block 指的是 Statements,而 Helpers 指的是 ClassFeatures。

T4 示例:

<# // This is a Statement #>
<#+ // This is a ClassFeature #>

确实,Statements 不能出现在 T4 中的 ClassFeatures 下面,但我认为这里发生的是 Visual Studio T4 对 ttinclude 文件进行“智能”合并。 Mono T4 可能没有。

了解为什么要考虑这两个 T4 文件。

示例 T4.ttinclude:

<# // 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 设计的,它使用稍微更精细的包含策略。

如果这是你需要的原因

  1. 重构 SQLLite.ttinclude 或 Settings.ttinclude 以仅使用 ClassFeatures。这可能是一次重大重构,因为在 .ttinclude 文件中包含语句非常方便。
  2. 重构 Mono T4 以执行与 Visual Studio T4 类似的操作

我担心这也不是好消息。

附言。在阅读 Mono 代码时,开发人员似乎考虑了这一点:

//TODO: are blocks permitted after helpers?  
throw new ParserException ("Blocks are not permitted after helpers", seg.StartLocation);   

关于c# - 尝试在 sharpdevelop 中执行 subsonic 的 activerecord 时出现 T4 模板生成错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7137874/

相关文章:

c# - 使一种类型适应另一种类型的最佳 OO 实践?

bash - 将 sqlite 输出移动到 bash 数组

c# - docker run 中功能主机未运行错误

java - 将初始数据插入到sqlite android

c++ - Valgrind 在 sqlite3_step 中报告未初始化的值

ruby - Rails 根据日期输入自动填充表单字段

ruby-on-rails - rails : Data too long for column

activerecord - 如何向没有 id 列的现有表添加 uuid 主键

c# - 为什么 SQL 查询不运行?

c# - 是否可以在 NHibnernate IQueryable 中按类类型排序