/// <summary>
/// 获取一个类指定的属性值
/// </summary>
/// <param name="info">object对象</param>
/// <param name="field">属性名称</param>
/// <returns></returns>
public static object GetPropertyValue(object info, string field)
{
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);
}
本文介绍了一种通过反射获取.NET对象指定属性值的方法,并提供了一个示例代码片段。该方法适用于需要动态获取对象属性值的场景。

被折叠的 条评论
为什么被折叠?



