获取一个类指定的属性值
Posted 没有热枕,世间便无进步.
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了获取一个类指定的属性值相关的知识,希望对你有一定的参考价值。
/// <summary> /// 获取一个类指定的属性值 /// </summary> /// <param name="info">object对象</param> /// <param name="field">属性名称</param> /// <returns></returns> public static object GetPropertyValue(object info, string field) { try { if (info == null) return null; Type t = info.GetType(); IEnumerable<System.Reflection.PropertyInfo> property = from pi in t.GetProperties() where pi.Name.ToLower() == field.ToLower() select pi; return property.First().GetValue(info, null); } catch (Exception ex) { string msg = ex.Message.ToString(); return null; } }
以上是关于获取一个类指定的属性值的主要内容,如果未能解决你的问题,请参考以下文章