Dynamic Component plugging
Before implementing dynamic component plugging, we must understand the concept of Reflection ).
Reflection creates an object based on its name.
For example, in the above example, I can directly specify a string: "CSharpClassNameSpace. CSharpRect ", then I can generate this object and call its Area () method to find the Area! The precondition is that the program can access the DLL files that store these classes.
Now let's talk about our ideas:
We put the DLL used by a program and the class name in a configuration file. When the program starts, it can read the file and automatically load the externally specified DLL, implement dynamic assembly of program components. When I need to replace a component in the program, I just need to copy the new DLL to the program folder and the system will be able to use the new component immediately, instead of re-compiling or modifying any original code of the component caller!
Now let's take a look at our example!
We create two VB class libraries, each of which encapsulates a form. The VBDynamicComponent component encapsulates the following forms:
Figure 6 component 1
The VBDynamicComponent2 component encapsulates the following forms:
Figure 7 Component 2
The main program is a Windows application. It can dynamically create any form object in two components and display them:
Figure 8 main form of the sample program
At startup, the main program reads a system configuration list in XML format, as shown below:
The main program loads the specified component DLL file according to the list, and creates an object based on the ComponentName attribute value. The component form arranged in the first place is automatically displayed.
Let's take a look. Isn't such a system component assembly list like a raw material list for a cook preparing a big meal? Now, let's start making our "all-round banquet!
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