C#如何获取object对象的属性值(type反射)
2014-03-13 10:19
513 查看
/// <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);
}
///
获取一个类指定的属性值
///
</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);
}
相关文章推荐
- C#如何获取object对象的属性值
- C#如何获取object对象的属性值
- C#如何获取object对象的属性值
- Object对象如何类获取对应类的属性值
- 在FormView控件中嵌套数据绑定控件的问题,以及从一个对象中反射获取属性值的简单办法
- 通过反射获取某个对象下的属性值,或通过父类获取
- 10-10 arguments存储实参、解决js获取CSS属性值兼容性、object对象、for语句遍历对象内容、数组中的方法
- java使用反射机制根据属性名获取object对象指定属性的值
- java反射之Field 获取对象属性及设置属性值
- 反射获取对象的属性值
- java反射获取对象的属性值和对象属性中的子属性值
- Java通过反射获取和设置对象的属性值
- 如何使用反射取得对象的属性值
- java反射获取一个object属性值代码解析
- Java - 如何通过反射获取和设置对象私有字段的值?
- Java反射获取对象VO的属性值(通过Getter方法)
- 反射获取对象的属性值
- JAVA 反射获得object对象对应的实体类的属性、及属性值
- 利用反射获取实例化后的对象的属性及其属性值
- 反射获取类的属性和对象的属性值