Mcad学习笔记之通过反射调用类的方法,属性,字段,索引器(2种方法).docVIP

  • 5
  • 0
  • 约1.06万字
  • 约 11页
  • 2017-06-08 发布于重庆
  • 举报

Mcad学习笔记之通过反射调用类的方法,属性,字段,索引器(2种方法).doc

Mcad学习笔记之通过反射调用类的方法,属性,字段,索引器(2种方法)

Type是System.Reflection功能的根 (Root),也是存取Metadata的主要方法. 使用Type的成員可以取得相關資訊,例如建構函式(Constructor),方法,字段,屬性和類別的事件,以及模組和部署類別的組件(Assembly). 3種取得Type的方法: 1.靜態方法 Type.GetType() 2.運算符 typeof() 3.實例的方法GetType Employee e=new Employee(); e.GetType() 在一般情況下我們调用的方法並传递给它们的参数,某些情况下可能希望根据用户操作动态调用方法. 通过Reflection命名空间 方法1是使用Type对象上的InvokeMember方法 方法2是使用MethodInfo对象上的Invoke方法 example: 先定義類Employee 其中有靜態屬性Data 實例屬性Name,ID 2個索引器 ????///?summary ????///?自定義類 ????///?/summary ????public?class?Employee ????{ ????????string?name; ????????int?id; ????????ArrayList?list;? ????????static?int?data; ???????? ????????//ins

文档评论(0)

1亿VIP精品文档

相关文档