You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

49 lines
1.1 KiB

  1. using OT.COM.ArsenalDB;
  2. using OT.COM.LogisticsUtil;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Data;
  6. using System.Linq;
  7. using System.Reflection;
  8. namespace CounsellorBL.Helper
  9. {
  10. public static class EntityHelper
  11. {
  12. public static List<T> FromDataTable<T>(List<DataRow> i_dt) where T : EntityBase, new()
  13. {
  14. List<T> lRes = new List<T>();
  15. if (i_dt != null && i_dt.Any())
  16. {
  17. PropertyInfo[] pis = typeof(T).GetProperties();
  18. DataColumnCollection dcc = i_dt[0].Table.Columns;
  19. foreach (DataRow dr in i_dt)
  20. {
  21. T tCur = new T();
  22. foreach (PropertyInfo pi in pis)
  23. {
  24. if (!dcc.Contains(pi.Name) || dr[pi.Name] is DBNull)
  25. {
  26. continue;
  27. }
  28. ClassHelper.SetValueByPropertyName(tCur, pi.Name, dr[pi.Name]);
  29. }
  30. lRes.Add(tCur);
  31. }
  32. }
  33. return lRes;
  34. }
  35. }
  36. }