Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static List<T> Map<T>(DataTable data) where T : class, new()
- {
- List<T> list = new List<T>();
- foreach (var row in data.AsEnumerable())
- {
- T obj = new T();
- foreach (DataColumn column in data.Columns)
- {
- var property = obj.GetType().GetProperty(column.ColumnName);
- if (property != null)
- {
- if (column.DataType == property.PropertyType)
- property.SetValue(obj, row.Field<object>(column.ColumnName), null);
- }
- }
- list.Add(obj);
- }
- return list;
- }
Advertisement
Add Comment
Please, Sign In to add comment