码迷,mamicode.com
首页 > 其他好文 > 详细

随便写了点反射用例

时间:2014-09-02 19:26:15      阅读:195      评论:0      收藏:0      [点我收藏+]

标签:io   ar   for   cti   sp   on   c   new   ad   

public static T[] ObjectsFieldNameChange<T>(T[] records)
{
if (records == null)
return records;
if (records.Count() <= 0)
return records;

var type = records.FirstOrDefault().GetType();
var listType = records.GetType();
var propertys = type.GetProperties();

if (propertys.Count() <= 0)
return records;

Dictionary<string, string> userDefineList = ClientCache.CacheCode.Where(q => q.fListName == UserDefineHeader).ToDictionary(q => q.fCodeName, q => q.fCodeValue);

if (userDefineList.Count() <= 0)
return records;

foreach (PropertyInfo property in propertys)
{
var userDefine = userDefineList.Where(q => q.Key.Contains(property.Name));
if (userDefine.Count() > 0)
{
var attributes = property.GetCustomAttributes(false);
for (int i = 0; i < attributes.Count(); i++)
{
if (attributes[i] is DisplayNameAttribute)
{
attributes[i] = new DisplayNameAttribute(userDefine.FirstOrDefault().Value);
}
}
}
}
return records;
}

 

随便写了点反射用例

标签:io   ar   for   cti   sp   on   c   new   ad   

原文地址:http://www.cnblogs.com/zhuzhenpeng/p/3951996.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!