DataTable 转为 List<dynamic>
static List<dynamic> DataTableToListDynamic(DataTable dt)
{
List<dynamic> dynamicList = new List<dynamic>();
foreach (DataRow row in dt.Rows)
{
dynamic dynamicObj = new ExpandoObject();
var expandoDict = (IDictionary<string, object>)dynamicObj;
foreach (DataColumn column in dt.Columns)
{
expandoDict[column.ColumnName] = row[column];
}
dynamicList.Add(dynamicObj);
}
return dynamicList;
}
static List<dynamic> DataTableToListDynamic(DataTable dt)
{
List<dynamic> dynamicList = new List<dynamic>();
foreach (DataRow row in dt.Rows)
{
dynamic dynamicObj = new ExpandoObject();
var expandoDict = (IDictionary<string, object>)dynamicObj;
foreach (DataColumn column in dt.Columns)
{
expandoDict[column.ColumnName] = row[column];
}
dynamicList.Add(dynamicObj);
}
return dynamicList;
}