黎明的剔透里伸出了你沁清的暧昧

Graphics|EngineDev|GameDev|2D&3D Art

  C++博客 :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  60 随笔 :: 1 文章 :: 18 评论 :: 0 Trackbacks
 1 /// <summary>
 2           /// 将集合类转换成DataTable
 3          /// </summary>
 4          /// <param name="list">集合</param>
 5           /// <returns></returns>
 6           public static DataTable ToDataTable(IList list)
 7           {
 8               DataTable result = new DataTable();
 9               if (list.Count > 0)
10               {
11                  PropertyInfo[] propertys = list[0].GetType().GetProperties();
12                   foreach (PropertyInfo pi in propertys)
13                   {
14                       result.Columns.Add(pi.Name, pi.PropertyType);
15                   }
16    
17                   for (int i = 0; i < list.Count; i++)
18                  {
19                       ArrayList tempList = new ArrayList();
20                       foreach (PropertyInfo pi in propertys)
21                       {
22                           object obj = pi.GetValue(list[i], null);
23                           tempList.Add(obj);
24                       }
25                       object[] array = tempList.ToArray();
26                       result.LoadDataRow(array, true);
27                   }
28               }
29               return result;
30          }
posted on 2016-07-10 20:38 情绝格调(fresmaster) 阅读(364) 评论(0)  编辑 收藏 引用 所属分类: Coding

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理