标签:turn ring datatable tar contains equals property tostring obj
public class ListUtil { public static List<T> ToList<T>(DataTable dt) { List<T> list = new List<T>(); T t = default(T); PropertyInfo[] propertyinfos = null; foreach (DataRow dr in dt.Rows) { t = Activator.CreateInstance<T>(); propertyinfos = t.GetType().GetProperties(); foreach (PropertyInfo pro in propertyinfos) { if (dt.Columns.Contains(pro.Name)) { object value = dr[pro.Name]; if (!value.ToString().Equals("")) { pro.SetValue(t, value.ToString(), null); } } } list.Add(t); } return list; } }
标签:turn ring datatable tar contains equals property tostring obj
原文地址:http://www.cnblogs.com/z-huan/p/7307049.html