[英]Modify t4 template to generate write text in two files
我的實體模型(MyModel)具有MyModel.tt。 我需要修改MyModel.tt文件。 我想要的是我的simpleProperties寫在一個類中,而NavigationProperties和complexProperties寫在另一類中。 我找到了這些行,但是現在完全空白了。
這是(我認為)必須編寫將在不同類中寫入屬性的代碼。
<#
}
var simpleProperties = typeMapper.GetSimpleProperties(entity);
if (simpleProperties.Any())
{
foreach (var edmProperty in simpleProperties)
{
#>
// TODO: Write this in entityName.cs
<#=codeStringGenerator.Property(edmProperty)#>
<#
}
}
if (complexProperties.Any())
{
#>
<#
foreach(var complexProperty in complexProperties)
{
#>
// TODO: Write this in entityNameComplex.cs
<#=codeStringGenerator.Property(complexProperty)#>
<#
}
}
我不確定您是在問如何編寫“ codeStringGenerator”存根,還是只是將輸出分成兩個文件。 如果您只是想將輸出分成兩個文件,則下面的小片段應該可以使用。
<#
relativeOutputFilePath = @"\Output\" + oneTable.Name + "_List.aspx";
TemplateHelper.WriteTemplateOutputToFile(relativeOutputFilePath, Host, GenerationEnvironment);
GenerationEnvironment = new System.Text.StringBuilder();
#>
本質上,所有這些操作都是獲取到目前為止您模板所構建的字符串,將其寫入您選擇的文件,然后為下一個模板重置該字符串。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.