我使用的是 Visual Studio 2010,并安装了有形的 T4EditorPlusModellingTools。
我只是在玩 T4,以前从未接触过它。我想做的是查看项目中的一个类,然后写出每个属性。
谁能给我关于 .tt 文件结构的绝对初学者提示?我用谷歌搜索了这个,但没有找到答案,所以我们将不胜感激。
谢谢。
最佳答案
在标签中使用反射。
类似于:
<#foreach (PropertyInfo info in myObject.GetType().GetProperties()){#>
// do what you want with or any other property of info <#=info.Name#>
<#}#>
在这里尝试教程 msdn
<#@ template debug="false" language="C#" #>
<#@ output extension=".txt" #>
<#@ assembly name="System.Xml"#>
<#@ import namespace="System.Xml" #>
<#@ import namespace="System.Reflection" #>
<#
XmlDocument doc = new XmlDocument();
foreach (PropertyInfo info in doc.GetType().GetProperties()){#>
<#=info.Name#>
<#}#>
将打印 xmldocument 的所有属性
关于asp.net-mvc - 如何在 VS2010 中获取 T4 以迭代类的属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3248078/