您的位置:首页 > 其它

T4模板读取某个类的所有字段

2015-10-10 15:19 78 查看
这个文章的初衷只是方便自己,为的是以后可以快速找个备份。

注:用SortedList是为了自动排序。
在工作经常碰到A对象与B对象相似度90%然后就可以用下面的代码稍稍改进一下便可省去不少事,根因手笨经常出错,所以能复制复制,能不用手的全不用手。
如果有更好的办法,欢迎留言.

Love is real when shared!



<#@ template debug="false" hostspecific="false" language="C#" #>
<#@ output extension=".cs" #>
<#@ import namespace="System" #>
<#@ import namespace="System.Collections.Generic" #>
<#@ import namespace="System.Reflection" #>
<#@ assembly name="D:\testDll\Test.MyMode.dll" #>

<#
var typ = GetProperties();
foreach(var p in typ)
{
#><#=p.Value#>
<#}
#>

<#+
public SortedList <string,string> GetProperties(){
var res=new SortedList <string,string>();
foreach (PropertyInfo propertyInfo in typeof(Test.MyMode.WareInfoEntity).GetProperties())
{
res.Add(propertyInfo.Name,propertyInfo.Name);
}
return res;
}
#>


  
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: