把企业库返回的DataTable转换成实体列表

快下班了,没时间解释,直接上代码了。

 

class EntityHandler<EntityObject> where EntityObject : new() { /// <summary> /// 填充对象列表 /// </summary> public static List<EntityObject> ReceiveEntity(DataTable dt) { List<EntityObject> entityList = new List<EntityObject>(); foreach (DataRow dr in dt.Rows) { //EntityObject entityObject = (EntityObject)Activator.CreateInstance(typeof(EntityObject)); EntityObject baseEntity = new EntityObject(); foreach (PropertyInfo propertyInfo in typeof(EntityObject).GetProperties()) { baseEntity.GetType().GetProperty(propertyInfo.Name).SetValue(baseEntity, dr[propertyInfo.Name], null); } entityList.Add(baseEntity); } return entityList; } }

你可能感兴趣的:(null,Class)