How to implement dynamic function module loading via reflection

Source: Internet
Author: User

Assemblies contain modules, and modules contain types, and types also contain members. Reflection provides an object that encapsulates assemblies, modules, and types. You can use reflection to dynamically create an instance of a type, bind the type to an existing object, or get a type from an existing object. You can then invoke a method of the type or access its fields and properties.

We'll show you how to load a functional module by not using reflection and using reflection. Implementation results:

1. WinForm Main program

The main program we use WinForm Program, VS2008 tools C # language development. Includes toolbars, status bars, and TabControl controls. We use TabControl as a function module container to load each function module. The implementation results are as follows:

2. Do not use the reflection mode to load the function

Added information material function module project, Project Add Data Management (uccustomerinfo) user control. Data management display, load, import, export data functions.

2.1. WinForm Main program Call

WinForm Add a Data management project reference. When you click on the information material, the instance data management function module is loaded.

3. Load function using reflection mode

Using the reflection mode to load the function, you need to define the function module interface, design the configuration function module, the main program read the configuration file dynamic load function module.

3.1. Define the function module interface

The Function Module interface (UCMODULE) is defined as the user control (UserControl), the virtual two methods, for the specific function module to rewrite.

3.2. Implement the Function module instance

The function module is also the former information management function, but does not inherit the user control (UserControl), but inherits the function module interface (ucmodule).

3.3. Design Function Module Configuration

The function module configuration is defined by an XML file defined as: module number, module name, module project, module object.

3.4. By configuring the Dynamic function module

Read the function module configuration and return a list of system-defined functional modules. Add the toolbar button, and when you click the toolbar button, load the configured function module project.

At this point, how to dynamically load the function module by reflection has been explained. From the way the two examples are implemented, it is clear that dynamic loading is much more complex than the way it is used, so it is better to not use reflection in small projects, with few team members.

How to implement dynamic function module loading via reflection

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.