Recently began to learn. Net, encountered a relatively good open source IDE sharpdevelop. The development tool, developed using C #, is one of the things that attracts me is that it uses plug-in technology like eclipse to implement the entire system. And this plugin system is my most interesting place, so began a piece of code research. After this article, I will gradually write down my research experience. Because it is in the Internet café, there are a lot of inconvenience, so it may drag a long time.
I. Basic CONCEPTS
First of all, we first have a more perceptual understanding of sharpdevelop. You can download it from here to its executable program and code package http://www.icsharpcode.com/, install the nonsense will not say, first run a look. Does it feel like vs.? But the current version is 1.0.0.1550, there are many places to improve. About the code and system structure, sharpdevelop three authors wrote a book, you reader can refer to, but I have seen a lot of places do not understand.
Then, let me explain what it is called plug-ins and why you should use the plug-in system. Our previous systems, developers compiled and released, the system is not allowed to make changes and extensions, if you want to expand a feature, you must modify the code to recompile the release. This brings us a relatively large inconvenience. There are a number of solutions, such as providing configuration and so on. In the solution, Plug-ins are a better solution. You must know Photoshop, Winamp, they all have the concept of "plug-in", allowing other developers to write extensions based on the system's intended interface (for example, various filters in Photoshop). The so-called plug-in is the system's extended function module, this module is in the form of an independent file, and the system is relatively independent. During the system design, do not know the specific functions of plug-ins, only in the system for the plug-in left a predetermined interface, the system started according to the plug-in configuration to find Plug-ins, according to the intended interface to plug the plug-in system.
What kind of advantages does this approach bring? The first is the expansion of the system greatly enhanced, if we need to expand the system after the system is released, do not have to recompile, only need to modify the plugin on it. The second is advantageous and the team development, each function module because is in the form of the plug-in manifests in the system, the system daily construction is very simple, does not cause the entire system build failure because of a certain module error. The only thing that fails is a plugin.
Photoshop and Winamp plug-in systems are relatively simple, they first implemented a basic system, and then on the basis of this system to hook up other extensions of functional plug-ins. and SharpDevelop plug-in system is more powerful, its entire system based on just a plug-in management system, and you see all the interface, features are all in the form of plug-ins hanging. In such a plug-in system, we can not modify the basic system, only the use of plug-ins to construct a variety of different systems.
Now let's take a look at its plug-in system. Into the SharpDevelop installation directory, the SharpDevelop.exe and SharpDevelop.Core.dll in the bin directory are the basic plug-in systems for this system. In the AddIns directory there are two suffixes of addin files, one of which Sharpdevelopcore.addin is the definition (configuration) file of its core plug-ins, and the various functional modules defined therein exist in Bin\sharpdevelop.base.dll In the file, there are many other plug-ins that are defined in the addin file in the AddIns directory.
To analyze SharpDevelop's code, you first need to figure out a few basic concepts that are different from what I had previously imagined, and I went into the code to find out where my confusion was.
1. Addintree Plugin Tree
The plug-ins in SharpDevelop are organized into a plug-in tree structure defined by the path (path) defined in Extension (extension points), similar to the directory structure of a file system. Each plug-in in the system specifies the Extension in the configuration file and hangs to the plugin tree through the Path specified in Extension. In the system, the Addtreesingleton object can be used to access each plug-in to realize the interaction between plug-ins.
2, AddIn Plug-ins
In the SharpDevelop concept, a plug-in is a collection of multiple functional modules (rather than a functional module I used to think). In the form of the file is a AddIn configuration file, which corresponds to the AddIn class in the system.
3, Extension extension point
Each plug-in in the SharpDevelop is attached to the Addintree (plug-in tree), and the location of the plug-in tree is specified by Path in the plug-in's Extension object. In the addin configuration file, corresponds to <Extension>. For example, the configuration of the following function module
<extension Path = "/sharpdevelop/workbench/ambiences" >
<class id = ". NET" Class = "ICSharpCode.SharpDevelop.Services.NetAmbience"/>
</Extension>
Specifies that the extension point path is/sharpdevelop/workbench/ambiences, which is the position in the plug-in tree.
4, codon
This is a more difficult to understand things, in the sharpdevelop of the three authors of the book translated into the Code, is a bad translation, can be with handle (handle) a spell. The dictionary also has a translation called "Base code", I think this is not good, but also a little bit of meaning.
According to my understanding of the Code, codon describes (packaging) a functional module, a function module corresponds to a Command class that implements the specific functions. To facilitate access to the functional modules in each plug-in, codon defines basic properties for various functions, namely ID (the identity of the functional module), Name (function module type). Don't get me wrong, this name is the name of the XML node of the codon in the AddIn file definition, the ID is the real name, where name may be Class (class), MenuItem (menu item), Pad (panel), and so on. Depending on the specific function module, you can inherit codon to define some other attributes, SharpDevelop define Classcodon, Menucodon, Padcodon, and so on.
In the addin definition file, codon corresponds to the content under the <Extension> label. For example, the following definition
<extension Path = "/sharpdevelop/workbench/ambiences" >
<class id = ". NET" Class = "ICSharpCode.SharpDevelop.Services.NetAmbience"/>
</Extension>
<extension ...> internally defines a codon,<class ...> that the codon is a class (class), and then defines the codon's ID and the class name ICSharpCode.SharpDevelop.Services.NetAmbience that implements the codon. The runtime will find the corresponding class and create it by reflection, which we cannot implement in the previous language.
Again for example this definition
<extension Path = "/sharpdevelop/views/projectbrowser/contextmenu/combinebrowsernode" >
<menuitem id = "Compile"
label = "${res:xml.mainmenu.runmenu.compile}"
class = "ICSharpCode.SharpDevelop.Commands.Compile"/>
<menuitem id = "Compileall"
label = "${res:xml.mainmenu.runmenu.compileall}"
class = "ICSharpCode.SharpDevelop.Commands.CompileAll"/>
<menuitem id = "combinebuildgroupseparator" label = "-"/>
....
</Extension>
This extension point defines three menu items, as well as the name, label, and implementation class name of each item. The codon here corresponds to the Menucodon object in the system.
5. Command Order
As mentioned earlier, codon describes a functional module, and each functional module is a ICommand implementation. The most basic command is Abstractcommand, which corresponds to a different command according to the codon. For example Menucodon corresponds to MenuCommand and so on.
6, service services
In a plug-in system, there are functions that the entire system will use, such as file access, resources, messages, and so on. As a basic function of the plug-in system, these functions serve the whole system, and we call it "service". For ease of access, these services are uniformly managed through ServiceManager. In fact, the service is also a type of plug-in, their extension point path in the directory tree in the/services.
After you have understood these basic concepts, you can look at the SharpDevelop code. Look from the Src\main\startup.cs, then Addin.cs, AddinTree.cs and so on.
I've been writing for two hours and have a rest. And listen to let's.
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