Putting It All Together (A Simple Type Browser)
To show how easy it is to create a .NET type browser using reflection we put together a simple application called Discover that will allow you to browse a directory for any stored assembly (.DLL or .EXE). Once you select an assembly, you can click the Discover button and the application will fill a Tree control with information about that assembly. Figure 2
shows the Discover utility in action.
The information that the Discover application displays is all types in a given assembly, all the members of a given type, all the methods of a given type, and each method's parameters and data types. Displaying this information with reflection is remarkably easy. Listing 2
presents the code that loads the assembly and builds the tree. This code should be familiar to you, as it has been presented in previous sections of this article.
Hopefully the information in this article will allow you to add reflection as a new tool to your programmer's tool belt. It may not be the tool you'll reach for in typical programming situations, but given the right task, it can provide you with a lot of power.
In Part 2 of our reflection series we'll explore using the System.Reflection.Emit namespace to generate code at runtime.
All of the code for this article can be downloaded from www.brilliantstorm.com/resources.