Based on the component. NET software Development (3)

Source: Internet
Author: User
Dynamic component Plug and pull
Before implementing dynamic component interpolation, we must understand a concept: reflection (Reflection).

Reflection is the creation of an object by name only.

For example, in the above example, I can directly give a string: "Csharpclassnamespace.csharprect", and then I can generate this object, and call its area () method to find the size! The prerequisite is that the program can access the DLL file that holds these classes.

Well, now we can talk about our ideas:

We put a program to use the DLL and the class name in a configuration file, when the program started reading this file, you can automatically load the external specified DLL, implement the program's component dynamic assembly. When I need to replace a component in a program, I just need to copy the new DLL to the program folder, and the system can use the new component immediately without recompiling or modifying any of the original code of the component caller!

Now let's see how our example is!

We created two VB class libraries, each of which encapsulates a form. The following forms are encapsulated in the Vbdynamiccomponent component:



Figure 6 Component One

The following forms are encapsulated in the VBDynamicComponent2 component:



Figure 7 Component Two

The main program is a Windows application that dynamically creates any of the form objects in two components and displays them:



Figure 8 sample Program main form

The main program reads a list of system configurations at startup, which is in XML format, as follows:



<?xml version= "1.0" encoding= "GB2312"?>

<Config>

<component componentname= "Dynamiccomponent.vbform1" componentfilename= "DynamicComponent.dll"/>

<component componentname= "Vbdynamiccomponent2.vbform2" componentfilename= "VBDynamicComponent2.dll"/>

</Config>



The main program loads the specified component DLL file according to the manifest and creates the object based on the ComponentName property value, and the component form arranged in the first position is automatically displayed.

Let's take a look at such a system assembly list, like a list of raw materials as a chef prepares a big meal? Start making our "Feast" right now!




Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.