PropertyInfo 如何给属性中可为空的赋值
public static T PopulateEntityFromCollection<T>(T entity, IData逐显儿溶亲Reader collection) w有胞货晚here T : new()
//初始化 如果为null
if (entity == null)
entity = new T();
//得到类型
Type type = typ雷仍预东eof(T);
//取得属性集合
P意福远创粉群ropertyInfo[] pi = type.GetProperties();
foreach (Pro斤袁众pertyInfo item in p让为县画心满还副编聚i)
//给属性赋值
if (colle脱重标晶技天风采雷ction[***.Name] != null)
item.SetValu景范族衡代改发盟雨地e(entity, Convert.ChangeType(collection[***.Nam省迫巴制经西e], item.Prope力杀距rtyType), null);
return entity;
爱资源吧版权声明:以上文中内容来自网络,如有侵权请联系删除,谢谢。