Components used in the design example
Create two VB. NET class library projects: DynamicComponent and VBDynamicComponent2. Create two forms, VBForm1 and VBForm2, respectively (as shown in Figure 6 7). The former is placed in the DynamicComponent project and the latter is placed in the VBDynamicComponent2 project.
Compile and generate two DLL files: DynamicComponent. dll and VBDynamicComponent2.dll.
Next, we create a Windows application VBTestDynamicComponent to test our component assembly technology.
Read XML configuration files
When the test program starts, it reads information from the XML configuration file. We can see that the relevant information can be divided into two categories: one is the list of DLL files to be loaded, the other type is the name of the class to be loaded. Therefore, we can create two arraylists, one for storing the file name and the other for storing the class name. Then, we can encapsulate these two arraylists using a class MyComponentList, external users can get both the file name and class name immediately by providing the index.
Class interface design:
Figure 9 classes used to dynamically load components
See Figure 9. If you specify an XML configuration file name for an object in the MyComponentList class and call beginRead (), the caller can Index (, 2 ......) To obtain the file name and class name.
You can use the XmlTextReader class provided by. NET framework to read XML format data. The complete code is as follows:
'Read the class name and file name of the component from the XML configuration file.
Imports System. Collections. Specialized
Imports System. Windows. Forms
Public Class MyComponentList
Private xmlreader As Xml. XmlTextReader
Private _ FileName As String 'XML configuration file name
Private _ ComponentFileName As String 'component library file name
Class name in the Private _ ComponentName As String 'Component Library
Private componentNames As ArrayList stores the names of all component classes listed in the configuration file.
Private componentFiles As ArrayList stores the names of all component libraries listed in the configuration file.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service