123456789101112131415161718192021222324252627 |
- using Newtonsoft.Json;
- using System;
- using System.Collections.Generic;
- using System.Text;
- namespace System.Data
- {
- public static class DataTableExtension
- {
- public static IEnumerable<T> ToEntity<T>(this DataTable table) where T : class, new()
- {
- if (table != null && table.Rows.Count > 0)
- {
- var json = JsonConvert.SerializeObject(table);
- try
- {
- return JsonConvert.DeserializeObject<IEnumerable<T>>(json);
- }
- catch (Exception e)
- {
- return null;
- }
- }
- return null;
- }
- }
- }
|