.net T4模板的问题
我有下面的代码,它是给相关的花括号和东西.net T4模板的问题,.net,t4,.net,T4,我有下面的代码,它是给相关的花括号和东西 <#@ template language="C#" debug="True" hostspecific="True" #> <#@ output extension=".cs" #> <#@ assembly name="System.Data" #> <#@ assembly name="System.xml" #> <#@ import namespace="System.Collection
<#@ template language="C#" debug="True" hostspecific="True" #>
<#@ output extension=".cs" #>
<#@ assembly name="System.Data" #>
<#@ assembly name="System.xml" #>
<#@ import namespace="System.Collections.Generic" #>
<#@ import namespace="System.Data.SqlClient" #>
namespace MyProject.Entities
{
public class
{
<#
string connectionString =
"Server=localhost;Database=GridViewGuy;Trusted_Connection=true";
SqlConnection conn = new SqlConnection(connectionString);
conn.Open();
System.Data.DataTable schema = conn.GetSchema("TABLES");
foreach(System.Data.DataRow row in schema.Rows)
{
#>
public class <#= row["TABLE_NAME"].ToString() #>
{
}
}
}
}
名称空间MyProject.Entities
{
公共课
{
公共课
{
}
}
}
}
有人能发现问题吗 在第一个块中,启动一个代码块
foreach(System.Data.DataRow row in schema.Rows)
{
#>
但永远不要终止它。在下面的某个地方,你需要这个:
<# } #>
编辑-它看起来像是嵌套类定义下方的右大括号。它没有编译的原因是因为在
标记中没有对应的foreach块右大括号。您需要进行以下更改:
foreach(System.Data.DataRow row in schema.Rows)
{
#>
public class <#= row["TABLE_NAME"].ToString()#>
{
}
<#
} //this was missing.
#>
这可能不是您想要完成的。您应该安装Visual Studio的有形T4编辑器插件。它会给你匹配的大括号突出显示,使这类事情真的很容易搞清楚。有形是很酷的,直到你意识到intellisense是缓慢的,最多是不稳定的,你不能在模板中插入断点。
public class
{
public class Table1
{
}
public class Table2
{
}
//... and so on..
}