hao
2025-05-30 23a34e600fb4522aec09ad39b8a8ec2e008dcd51
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
using System;
using System.Collections.Generic;
using System.Data;
using System.Dynamic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace MES.Service.util
{
    public static class DataTableExtension
    {
        public static List<dynamic> ToDynamic(this DataTable dt)
        {
            var list = new List<dynamic>();
            foreach (DataRow row in dt.Rows)
            {
                dynamic obj = new ExpandoObject();
                var dict = (IDictionary<string, object>)obj;
                foreach (DataColumn col in dt.Columns)
                    dict[col.ColumnName] = row[col];
                list.Add(obj);
            }
            return list;
        }
    }
 
 
}