The following figure shows application’s only window loading .NET 2.0 mscorlib.dll and lists members of System.String.
All types (classes, structures, enumerations, etc.) inherit -directly or indirectly- from System.Type, and System.Type, in turn, inherits from System.Object. Therefore, System.Type can represent any other type.
All types related to reflection are grouped together inside the namespace System.Reflection in the core COR (Common Object Runtime) assembly, mscorlib.dll.
Reflection represents type members as objects inherit from System.Reflection.MemberInfo class. We will see how soon.
Visual Studio’s Object Browser and Class Viewer (WinCV) are the most illustrative examples of tools that use reflection to obtain information about types in a given assembly.
It allows you to select an assembly, and it lists types defined within that assembly it in the left pane. When you select a type, it automatically lists type members in the right pane of the window.
Shared fields. Retrieved using System.Type.GetFields() function.
Shared properties. Retrieved using System.Type.GetProperties() function.
Shared events. Retrieved using System.Type.GetEvents() function.
Shared methods. Retrieved using System.Type.GetMethods() function.
Shared constructors. Retrieved using System.Type.GetContructors() function.
Retrieved using System.Type.GetFields() function with BindingFlags.Instance flag set.
Retrieved using System.Type.GetProperties() function with BindingFlags.Instance flag set.
Retrieved using System.Type.GetEvents() function with BindingFlags.Instance flag set.
Retrieved using System.Type.GetMethods() function with BindingFlags.Instance flag set.
Retrieved using System.Type.GetContructors() function with BindingFlags.Instance flag set.
Every one of our System.Type.GetXXX() functions returns an array of types inherit from System.Reflection.MemberInfo class. This allows us to polymorphically enumerate the array and work with all class members the same way. The following illustration should give you a basic understanding of how types are related to each other.
Code sample and application are attached with the article. The setup file installs both the application and its source code.
I created this application since several years ago when I was discovering .NET for the first time. Honestly, the UI of this sample originated from a VB.NET book. I really know neither the name of that book nor the name of its author. However, a big €œThank You€ to the author and the book.