新浪博客

C#如何获取object对象的属性值

2013-07-15 20:12阅读:

C#如何获取object对象的属性值

/// <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.PropertyIn
fo> property = from pi in t.GetProperties() where pi.Name.ToLower() == field.ToLower() select pi;
return property.First().GetValue(info, null);
}

我的更多文章

下载客户端阅读体验更佳

APP专享