2013-04-10 24 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,它可能提供更多的信息。