ReflexCls.cs 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Reflection;
  5. namespace CarLocalMeter
  6. {
  7. public class ReflexCls
  8. {
  9. /// <summary>
  10. ///
  11. /// </summary>
  12. /// <param name="objs"></param>
  13. /// <param name="iType">0 Id查询 1非Id查询</param>
  14. /// <param name="strId">iType是0的时候strId则有值</param>
  15. /// <returns></returns>
  16. public static Dictionary<string, object> method(object[] objs, out int iType, out string strId)
  17. {
  18. iType = 1;
  19. strId = "";
  20. object value;
  21. Dictionary<string, object> dt = new Dictionary<string, object>();
  22. foreach (object obj in objs)
  23. {
  24. Type tp = obj.GetType();
  25. if (tp.IsClass)
  26. {
  27. PropertyInfo[] PropertyInfos1 = obj.GetType().GetProperties();
  28. foreach (PropertyInfo p1 in PropertyInfos1)
  29. {
  30. value = p1.GetValue(obj, null);
  31. if (value != null)
  32. {
  33. dt.Add(p1.Name, value);
  34. }
  35. }
  36. }
  37. }
  38. if (dt != null)
  39. {
  40. if (dt.Where(s => s.Key == "pageNum").Count() == 0)
  41. {
  42. dt.Add("pageNum", 1);
  43. }
  44. if (dt.Where(s => s.Key == "pageSize").Count() == 0)
  45. {
  46. dt.Add("pageSize", 999999);
  47. }
  48. }
  49. return dt;
  50. }
  51. }
  52. }