///转记录表到模型列表 ///模型类型 /// 记录表 ///模型列表 public static ListConvertToModelList (DataTable table) { List result = new List (); if (null == table || 0 == table.Rows.Count) { return result; } foreach (DataRow dr in table.Rows) { T model = Activator.CreateInstance (); // 如果失败就用这个方式:Activator.CreateInstance(assemblyName, typeName); Type type = model.GetType(); foreach (PropertyInfo property in type.GetProperties()) { string propertyName = property.Name; //property.SetValue(model, dr[propertyName], null); //try { property.SetValue(model, Convert.ChangeType(dr[propertyName], property.PropertyType), null); } catch { } property.SetValue(model, Convert.ChangeType(dr[propertyName], property.PropertyType), null); } result.Add(model); } return result; }