Free mag vol1 | Page 653

CHAPTER 15  TYPE REFLECTION, LATE BINDING, AND ATTRIBUTE-BASED PROGRAMMING Now, set a reference to the CommonSnappableTypes.dll assembly, but not the CSharpSnapIn.dll or VbSnapIn.dll code libraries. As well, import the System.Reflection and CommonSnappableTypes namespaces into your form’s primary code file (which you can open by right-clicking on the form designer and selecting View Code). Remember that the whole goal of this application is to make use of late binding and reflection to determine the “snapability” of independent binaries created by third-party vendors. Again, I won’t bother to examine all the details of Windows Forms development at this point in the text (see Appendix A). However, assuming you have placed a MenuStrip component onto the form designer, define a topmost menu item named File that provides a single submenu named Snap In Module. As well, the main window will contain a ListBox type (which I renamed as lstLoadedSnapIns) that will be used to display the names of each snap-in loaded by the user. Figure 15-8 shows the final GUI. Figure 15-8. GUI for MyExtendableApp The code that handles the Click event for the File Snap In Module menu item (which may be created simply by double-clicking the menu item from the design-time editor) displays a File Open dialog box and extracts the path to the selected file. Assuming the user did not select the CommonSnappableTypes.dll assembly (as this is purely infrastructure), the path is then sent into a helper function named LoadExternalModule() for processing (implemented next). This method will return false when