.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
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之间的优缺点