2015-11-02 56 views
2

我試圖執行T4 template來生成一些冗餘的csharp代碼。我的模板獲取傳入的對象類型,如下面的GenericTextFormatter<<#=type>>,其中類型爲typeof(objectA)等。所以我期望生成的輸出爲GenericTextFormatter<ObjectA>但是該模板在顯示外部斜角括號時遇到了問題,而我看不到此部分的輸出。如何在T4模板內輸出<Type>

+0

t4爲_text_模板,所以你應該傳遞給輸出不'type'對象,但是類型名稱,或者輸入全名 – Grundy

+0

的問題是上面描述了導致我的問題的代碼。我確信有人熟知T4模板必須以前看過。 – eYe

回答

3

你忘了關閉#。嘗試GenericTextFormatter<<#=type #>>

作爲參考,下面T4代碼輸出List<System.String>

<#@ template debug="false" hostspecific="false" language="C#" #> 
<#@ assembly name="System.Core" #> 
<#@ import namespace="System.Linq" #> 
<#@ import namespace="System.Text" #> 
<#@ import namespace="System.Collections.Generic" #> 
<#@ output extension=".txt" #> 

<# 
    var type = typeof(string); 
#> 

List<<#= type #>> 
+1

就是這樣,完全失去了我的專注,謝謝! – eYe