EntityBase.cs 959 B

123456789101112131415161718192021222324252627282930313233343536
  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 Common
  8. {
  9. public class EntityBase<T>
  10. {
  11. public M format<M>(T t,M m)
  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 (p2.Name.ToUpper() == p1.Name.ToUpper())
  21. {
  22. value = p1.GetValue(t, null);
  23. if (value != null)
  24. {
  25. p2.SetValue(m, value, null);
  26. }
  27. }
  28. }
  29. }
  30. return m;
  31. }
  32. }
  33. }