List<DocFlowInfo> listdoc = flowQueryBO.QueryProject(condition).Items.ToList();
DataTable result = new DataTable();
if (listdoc != null && listdoc.Count > 0)
{
PropertyInfo[] propertys = listdoc[0].GetType().GetProperties();
foreach (PropertyInfo pi in propertys)
{
Type colType = pi.PropertyType;
if ((colType.IsGenericType) && (colType.GetGenericTypeDefinition() == typeof(Nullable<>)))
{
colType = colType.GetGenericArguments()[0];
}
result.Columns.Add(pi.Name, colType);
}
for (int i = 0; i < listdoc.Count; i++)
{
ArrayList templist = new ArrayList();
foreach (PropertyInfo pi in propertys)
{
object obj = pi.GetValue(listdoc[i], null);
templist.Add(obj);
}
object[] array = templist.ToArray();
result.LoadDataRow(array, true);
}
}
转载于:https://www.cnblogs.com/changweiLi/p/3498959.html