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