摘要:
忘了為什么要把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
萊布尼茨
閱讀(9420)
評論(12)
推薦(2)

浙公網安備 33010602011771號