2013-04-10 75 views
1

我的MyModel.tt用于我的实体模型(MyModel)。我需要修改我的MyModel.tt文件。我想要的是我的simpleProperties在一个类中写入,而navigationProperties和complexProperties在其他类中写入。我找到了线,但现在完全空白做什么。修改t4模板以在两个文件中生成写入文本

这是代码(我认为)我必须编写代码,它将在不同的类中编写属性。

<# 
    } 
    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)#> 
<# 
     } 
    } 

回答

0

我不确定您是问如何编写您的“codeStringGenerator”存根或只是将输出分成两个文件。如果你只是想把输出分成两个文件,那么下面的小代码应该可以工作。

<# 
     relativeOutputFilePath = @"\Output\" + oneTable.Name + "_List.aspx"; 
     TemplateHelper.WriteTemplateOutputToFile(relativeOutputFilePath, Host, GenerationEnvironment); 
     GenerationEnvironment = new System.Text.StringBuilder(); 
#> 

从本质上讲这一切都为抢已由您的模板迄今建造的字符串,将它写入您选择的文件,然后重新设置下一个模板的字符串。

这是从这个StackOverflow post,它可能提供更多的信息。