Merge branch 'master' of https://gitee.com/frane-yang/SGGL_SeDin_New
This commit is contained in:
@@ -1214,6 +1214,31 @@ namespace BLL
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public static DataTable ToDataTable<T>(this T[] entities)
|
||||
{
|
||||
DataTable dataTable = new DataTable(typeof(T).Name);
|
||||
|
||||
PropertyInfo[] properties = typeof(T).GetProperties(BindingFlags.Public | BindingFlags.Instance);
|
||||
|
||||
foreach (PropertyInfo propInfo in properties)
|
||||
{
|
||||
dataTable.Columns.Add(propInfo.Name, propInfo.PropertyType);
|
||||
}
|
||||
|
||||
foreach (T entity in entities)
|
||||
{
|
||||
object[] values = new object[properties.Length];
|
||||
for (int i = 0; i < properties.Length; i++)
|
||||
{
|
||||
values[i] = properties[i].GetValue(entity);
|
||||
}
|
||||
|
||||
dataTable.Rows.Add(values);
|
||||
}
|
||||
|
||||
return dataTable;
|
||||
}
|
||||
/// <summary>
|
||||
/// 在设定的数值内产生随机数的数量
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user