C#如何获取object对象的属性值
2010-11-08 15:37
423 查看
using System.Linq;
/// <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);
}
if ($ != jQuery) {
$ = jQuery.noConflict();
}
/// <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);
}
if ($ != jQuery) {
$ = jQuery.noConflict();
}
相关文章推荐
- C#如何获取object对象的属性值
- Object对象如何类获取对应类的属性值
- C#如何获取object对象的属性值(type反射)
- C#如何获取object对象的属性值
- 10-10 arguments存储实参、解决js获取CSS属性值兼容性、object对象、for语句遍历对象内容、数组中的方法
- 如何在MapX下读取属性值、自定义范围专题图、在mapx中查找对象的方法
- Sencha Touch对象数组如何获取长度(有多少组)
- Sharepoint学习笔记—ECMAScript对象模型系列-- 3、如何查看SP object的所有方法(method)
- 如何快速获取properties中的配置属性值
- ASPxGridView对象中如何获取子表对象(DetailRow中的ASPxGridView:点击主表的行后展开的子表)的控制权?
- 通过GetCurrentObject和GetObject获取和hdc相关的位图对象数据区起始地址
- 如何获取对象的key
- java反射获取对象的属性值和对象属性中的子属性值
- 详解iPhone下如何获取对象一
- javascript如何获取触发事件的对象
- c# 如何通过反射 获取\设置属性值、
- List<Map<String,Object>>如何使用Java代码遍历以获取String,Object的值
- 在WPF中,如何得到任何Object对象的XAML代码?
- JSON格式讲解,JSON获取对象,JSONObject和JSONArray的操作
- Unity3D如何获取对象和子对象