CommonUtil.cs 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. using System.Reflection;
  2. namespace SHJX.Service.Library.Common
  3. {
  4. public class CommonUtil
  5. {
  6. /// <summary>
  7. /// 反射获取指定值
  8. /// </summary>
  9. /// <param name="obj"></param>
  10. /// <param name="path"></param>
  11. /// <returns></returns>
  12. public static object GetPropertyValue(object obj, string path)
  13. {
  14. //Type type = obj.GetType();
  15. //System.Reflection.PropertyInfo propertyInfo = type.GetProperty(path);
  16. //if(propertyInfo == null)
  17. //{
  18. // return null;
  19. //}
  20. //return propertyInfo.GetValue(obj, null);
  21. if (obj == null) return string.Empty;
  22. bool flag = !string.IsNullOrEmpty(path);
  23. object result;
  24. if (flag)
  25. {
  26. PropertyInfo property = obj.GetType().GetProperty(path);
  27. bool flag2 = property != null;
  28. if (flag2)
  29. {
  30. result = property.GetValue(obj, null);
  31. return result;
  32. }
  33. }
  34. result = obj;
  35. return result;
  36. }
  37. }
  38. }