| 1234567891011121314151617181920212223242526272829303132333435363738394041 |
- using System.Reflection;
- namespace SHJX.Service.Library.Common
- {
- public class CommonUtil
- {
- /// <summary>
- /// 反射获取指定值
- /// </summary>
- /// <param name="obj"></param>
- /// <param name="path"></param>
- /// <returns></returns>
- public static object GetPropertyValue(object obj, string path)
- {
- //Type type = obj.GetType();
- //System.Reflection.PropertyInfo propertyInfo = type.GetProperty(path);
- //if(propertyInfo == null)
- //{
- // return null;
- //}
- //return propertyInfo.GetValue(obj, null);
- if (obj == null) return string.Empty;
- bool flag = !string.IsNullOrEmpty(path);
- object result;
- if (flag)
- {
- PropertyInfo property = obj.GetType().GetProperty(path);
- bool flag2 = property != null;
- if (flag2)
- {
- result = property.GetValue(obj, null);
- return result;
- }
- }
- result = obj;
- return result;
- }
- }
- }
|