Reflection

参考文章

.NET Framework's Reflection API allows you to fetch Type (Assembly) information at runtime or programmatically. We can also implement late binding using .NET Reflection. At runtime, Reflection uses the PE file to read the metadata about an assembly. Reflection enables you to use code that was not available at compile time. 

一句话来说呢,reflection这个namespace就是帮助我们在编程时去获取或者去编辑一些runtime变量,常用的如下:

常用操作对象

 对于reflection来说,还有一个很重要的概念(Type)

The Type class and its members are used to get information about a type declaration and its members such as constructors, methods, fields, properties, and events of a class, as well as the module and the assembly in which the class is deployed.以下是三种方式可以用来获取type的info


获取type info的三种方法

System.object.GetType()将在编译时去获取对象的property信息

System.Type.GetType(),调用Type的static方法来获取对象的信息,This method gets the type with the specified name, performing a case-sensitive search.

typeof (),直接作用于object来获取对象的properties.

reflection的另外一个有用的工具:late binding,该方法允许我们可以在run-time时期去绑定一些数据和invoke对应的方法

未完,总结一些late binding 和 early binding之间的优缺点

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容