如何让VS2010中的T4迭代类的属性

Pau*_*aul 2 asp.net-mvc t4

我正在使用Visual Studio 2010,并安装了tangibleT4EditorPlusModellingTools.

我只是在玩T4,从未接触过它.我想做的是查看项目中的一个类,并写出每个属性.

任何人都可以给我绝对的初学者提示如何构建.tt文件?我用谷歌搜索了这个并没有找到答案,所以任何帮助都会受到赞赏.

谢谢.

tsi*_*nik 6

在标签中使用Reflection.

就像是:

<#foreach (PropertyInfo info in myObject.GetType().GetProperties()){#>
    // do what you want with or any other property of info <#=info.Name#>
<#}#>
Run Code Online (Sandbox Code Playgroud)

尝试这里的tuturials 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#>
<#}#> 
Run Code Online (Sandbox Code Playgroud)

将打印xmldocument的所有属性