public static class DataTableExtensions
{
public static List<dynamic> ToDynamic(this DataTable dt)
{
var dynamicDt = new List<dynamic>();
foreach (DataRow row in dt.Rows)
{
dynamic dyn = new ExpandoObject();
foreach (DataColumn column in dt.Columns)
{
var dic = (IDictionary<string, object>)dyn;
dic[column.ColumnName] = row[column];
dynamicDt.Add(dyn);
}
}
return dynamicDt;
}
}

posted on 2015-10-10 13:29  邢帅杰  阅读(294)  评论(0编辑  收藏  举报