Reflection Learning Notes (v) building an extensible application

Source: Internet
Author: User

Building a Scalable application
If an extensible application is pre-programmed to query the specified interface, it can determine at run time whether the type can be activated. Once the validation test passes, the type can support additional interfaces, providing multiple structures for their functionality.

Example:

Goal: Learn a simple interface programming process, use reflection, attributes to load external assemblies into memory at run time, and use

First step: Create a new solution

Two project files

Mextendableapp is the main project, Commonsnappabletypes is an extension project (providing interface standards, company information Description, functional information description)

Next, let's write the main project.

The main interface is very simple

Initialize a form

First, we want to load the third-party extension at runtime, we need to know the location of the third-party plug-in, here we run the program under the same directory to create a new folder for the third-party plug-in assembly files. not all classes in the assembly file implement interfaces iappfunctionality to determine which third-party custom types implement the interface iappfunctionality.

Next, manipulate the types that implement the interface iappfunctionality: Find the Doit method in these classes, and get the attributes defined on the doit method. These methods (when writing this code do not know what class names the third party will define, but you can use the Richter substitution principle to create the type object and return it as an interface type).

Finally, we define the event. Here's a very noteworthy point: how do you create a type object in an event and invoke a method of the type object? Sender is the initiator of the event, that is, ToolStripMenuItem, through its Tag property can pass the interface type object into the event, with the object, you can call the object's methods.

Such an extensible application is ready to write.

Next, we do a third-party application to test.

The test here is very simple, first of all, third-party companies to download the extension standard assembly files from the official web, that is, in the solution folder to add the folder reference, put the assembly into the folder, the next can be developed, remember to add the assembly file first.

Reflection Learning Notes (v) building an extensible application

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.