摘要: 忘了为什么要把IEnumerable<T>转成DataTable,不过这个需求应该挺常见,恰好今天看到以前的一段代码,有些想法就记录下来。IEnumerable<T>中的T是泛型,咱们就不能事先知道T都有哪些属性,因此创建出来的DataTable也就不能预先设置列。遇到这种情况,首先就想到反射。 1 public static DataTable ToDataTable<T>(IEnumerable<T> collection) 2 { 3 var props = typeof(T).GetProperties(); 4 var dt = new 阅读全文
posted @ 2013-01-09 15:51 莱布尼茨 阅读(9225) 评论(12) 推荐(2) 编辑