Пример #1
0
        /// <summary>
        /// Convert an object to datatable
        /// </summary>
        /// <param name="o">object</param>
        /// <returns></returns>
        public static DataTable ConvertToDataTable(this object o)
        {
            PropertyInfo[] properties = o.GetType().GetProperties();
            DataTable      dt         = ConverterDataHelper.CreateDataTable(properties);

            ConverterDataHelper.FillData(properties, dt, o);
            return(dt);
        }
Пример #2
0
        /// <summary>
        /// Convert object array to datatable
        /// </summary>
        /// <param name="array">object array</param>
        /// <returns></returns>
        public static DataTable ConvertToDataTable(this object[] array)
        {
            PropertyInfo[] properties = array.GetType().GetElementType().GetProperties();
            DataTable      dt         = ConverterDataHelper.CreateDataTable(properties);

            if (array.Length != 0)
            {
                foreach (object o in array)
                {
                    ConverterDataHelper.FillData(properties, dt, o);
                }
            }
            return(dt);
        }