public List<T> GetList<T>(DataTable dt) where T:new() { List<T> DateLists = new List<T>(); string Typename = ""; foreach (DataRow rows in dt.Rows) { T t = new T(); PropertyInfo[] info = typeof(T).GetProperties(); foreach (PropertyInfo pi in info) { Typename = pi.Name; if (dt.Columns.Contains(Typename)) { object value = rows[Typename]; if (value!=DBNull.Value) { if (pi.PropertyType.ToString()=="System.String") { pi.SetValue(t, System.Web.HttpUtility.HtmlDecode(value.ToString()), null); } else { pi.SetValue(t,value,null); } } } } DateLists.Add(t); } return DateLists; }
时间: 2024-10-19 00:22:29