EntityBase.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Reflection;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. namespace CarLocalMeter
  8. {
  9. public class EntityBase<T>
  10. {
  11. public M format<M>(T t, M m, List<string> list = null)
  12. {
  13. PropertyInfo[] PropertyInfos1 = t.GetType().GetProperties();
  14. PropertyInfo[] PropertyInfos2 = m.GetType().GetProperties();
  15. object value;
  16. foreach (PropertyInfo p2 in PropertyInfos2)
  17. {
  18. foreach (PropertyInfo p1 in PropertyInfos1)
  19. {
  20. if (list != null)
  21. {
  22. bool noChange = list.Contains(p2.Name);
  23. if (noChange)
  24. {
  25. break;
  26. }
  27. }
  28. if (p2.Name == "createManName" || p2.Name == "createManNo" || p2.Name == "createTime" || p2.Name == "updateManName" || p2.Name == "updateManNo" || p2.Name == "updateTime" || p2.Name == "valueFlag")
  29. {
  30. break;
  31. }
  32. if (p2.Name.ToUpper() == p1.Name.ToUpper())
  33. {
  34. value = p1.GetValue(t, null);
  35. if (value != null)
  36. {
  37. p2.SetValue(m, value, null);
  38. }
  39. }
  40. }
  41. }
  42. return m;
  43. }
  44. }
  45. }