FieldInfo学习心得
2014-03-27 22:55
148 查看
FieldInfo是反射应用中的类,它表示某个对象公共字段的信息。Type.GetField(string name)的返回类型为FieldInfo。例如知道对象objExample,其一个共有字段名为strName,则objExample.GetType().GetField(strName)可以获得对象中strName字段的信息。另外可以通过FileInfo的GetValue(Object obj)获得obj对象中该字段的值。应用:当知道某对象和该对象的某个公共字段名时,可以通过Type的GetField方法和FieldInfo的GetValue方法获得对象中该字段的值。
在MSDN中GetField(string name)的解释为:
// Summary:
// Searches for the public field with the specified name.
//
// Parameters:
// name:
// The System.String containing the name of the data field to get.
即该方法的作用是查询指定名字的公用字段,其中阐述name是所查询共有字段的名称。
MSDN中对FieldInfo.GetValue(Object obj)的解释为:
// Summary:
// When overridden in a derived class, returns the value of a field supported
// by a given object.
//
// Parameters:
// obj:
// The object whose field value will be returned.
//
// Returns:
// An object containing the value of the field reflected by this instance.
即该方法的作用是返回给定对象支持的字段的值,其中参数obj为包含该字段的对象。
在MSDN中GetField(string name)的解释为:
// Summary:
// Searches for the public field with the specified name.
//
// Parameters:
// name:
// The System.String containing the name of the data field to get.
即该方法的作用是查询指定名字的公用字段,其中阐述name是所查询共有字段的名称。
MSDN中对FieldInfo.GetValue(Object obj)的解释为:
// Summary:
// When overridden in a derived class, returns the value of a field supported
// by a given object.
//
// Parameters:
// obj:
// The object whose field value will be returned.
//
// Returns:
// An object containing the value of the field reflected by this instance.
即该方法的作用是返回给定对象支持的字段的值,其中参数obj为包含该字段的对象。
相关文章推荐
- 学习velocity的心得
- C++学习心得
- 遗传算法学习心得
- Spring学习心得(6)-- spring DI(依赖注入)
- Spring学习心得(8)-- IOC注解
- vss团队开发工具使用(个人学习心得)
- <<最小割模型在信息学竞赛中的应用>>的学习心得
- 数据库学习心得:在sql语句的各个语法之间的先后顺序是:可以任意的。
- Spring学习心得(17)-- 切入点表达式
- C++用法的学习心得
- 7月22日学习心得
- ios入门学习建议和方法,心得
- SET IDENTITY_INSERT-学习心得
- SSH框架学习心得
- elasticsearch系列-elasticsearch学习心得
- oracle 学习心得
- cuda学习心得--2.真正入手利用GPU计算加法
- HM学习心得--CU分割的认识
- COM技术内幕学习心得
- 四月学习心得