Team Fly |
Page 208
TextBox1.SelectionLength = 0 |
It's well and good to be able to thoroughly examine the types, members, and parameters within an assembly. But reflection has two additional tricks up its sleeve. You can also execute reflected code during runtime (as illustrated by the following example).
In the example in Listing 8.8, you provide the user with a list of methods in a ListBox. The user clicks on that list, and you then ask the user to type in the correct parameters required by the method they chose. Finally, you execute the method.
This illustrates how you can write a program that explores an unknown assembly (unknown at least to you, the programmer, while writing your code). Your program explores the unknown assembly, displays its classes and members during runtime, permits a user to choose among the displayed items, tells them what parameters to pass, and then executes the code from within the reflected classes.
Listing 8.8 ties together several of the techniques introduced throughout in this chapter. Start a new VB.NET project and add a TextBox, a label, a ListBox, and a button. Then type this in:
LISTING 8.8: EXPLORING AN UNKNOWN ASSEMBLY |
Imports System.Reflection |
Team Fly |