/// <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); }
/// <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); }