• 对象集合转换为datatable



      private static DataTable ToDataTable(IList list)
            {
                DataTable result = new DataTable();
                if (list.Count > 0)
                {
                    PropertyInfo[] propertys = list[0].GetType().GetProperties();
                    foreach (PropertyInfo pi in propertys)
                    {
                        if (pi.PropertyType.Name.IndexOf("Nullable") > -1)
                        {
                            result.Columns.Add(pi.Name, typeof(string));
                            continue;
                        }
                        result.Columns.Add(pi.Name, pi.PropertyType);
                    }

                    for (int i = 0; i < list.Count; i++)
                    {
                        ArrayList tempList = new ArrayList();
                        foreach (PropertyInfo pi in propertys)
                        {
                            object obj = pi.GetValue(list[i], null);
                            tempList.Add(obj);
                        }
                        object[] array = tempList.ToArray();

                        result.LoadDataRow(array, true);
                    }
                }
                return result;
            }
  • 相关阅读:
    require笔札
    zepto_core
    2016年规划
    说说Q.js中的promise的历史
    jQuery.extend
    jQuery.core_02
    javascript之this指针
    javascript之闭包
    javascript之作用域链
    jvavascript之变量对象
  • 原文地址:https://www.cnblogs.com/pan11jing/p/1743717.html
Copyright © 2020-2023  润新知