Browse DevX
Sign up for e-mail newsletters from DevX


Reflection Part I: Discovery and Execution : Page 5

Many developers see reflection as something new and mysterious. In the first of this two-part article we explain reflection in the .NET Framework and demonstrate where and how you can use this new tool in your applications.




Building the Right Environment to Support AI, Machine Learning and Deep Learning

Putting It All Together (A Simple Type Browser)
Figure 2: Discover dialog in action.
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.

Lars Powers, MCSD has over 10 years of experience analyzing business problems and developing software solutions. Most of his experience centers on leading development teams and writing software in Microsoft development environments. .
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date