The order recently started to learn .NET, encountered a relatively good open source IDE SharpDevelop. This development tool is developed using C #, which is more attractive to me to use plug-in technology similar to Eclipse to achieve the entire system. And this plugin system is the place I most interested in, so I started a study of a code. After this article, I will write down my study. Because it is online, there are many inconveniences, so it may be more dragging more time. First, the basic concept first, let's first have a relatively sensible understanding of SharpDevelop. You can download it from here to its executable and code package http://www.icsharpcode.com/, you don't say anything, let's take a look. Feeling with VS is like? However, the current version is 1.0.0.1550, and there are many places to be improved. With regard to code and system structure, three authors of SharpDevelop wrote a book, you can refer to it, but I still have a lot of places after I have seen it. Then, let me explain what plugin and why use the plugin system. Our previous system, developer compile, the system is not allowed to make changes and expansion, if you want to expand a feature, you must modify the code recompilation release. This brings us more inconvenience. There are many ways to solve, such as providing configurations such as configuration. In the solution, the plugin is a better solution. Everyone must know Photoshop, Winamp, they all have the concept of "plug-in", allowing other developers to write extensions (eg, various filters in Photoshop) based on the system predetermined interface (eg, various filters in Photoshop). The so-called plug-in is the system's extension function module, which occurs in the form of a separate file, and the system is relatively independent. During the system design, the specific function of the plugin is not known, just leave a predetermined interface for the plugin in the system, and the system is started according to the plugin according to the configuration of the plugin, and the plugin is attached to the system according to the predetermined interface. What kind of advantages have this way? The first is that the system's scalability is greatly enhanced. If we need to expand the system after the system is released, it is not necessary to recompile, just modify the plugin. Secondly, since the team is developed, each functional module is manifested in the system in the form of a plug-in, and the system's daily construction is very simple, and it will not cause the entire system to fail because of a module error. Failure is just a plugin. Photoshop and Winamp's plugin systems are relatively simple, and they first enable a basic system, then histed other extension function plugins on the basis of this system. SharpDevelop's plug-in system is more powerful, and its entire system is just a plug-in management system, and all interfaces you see are all hanging in the form of plugins. Under such a plug-in system, we can do not modify the basic system, just use a plugin to construct a variety of different systems. Let us look at its plugin system. In the installation directory of SharpDevelop, SharpDevelop.exe and SharpDevelop.Core.dll under bin directory are the basic plugin system for this system. There are two suffixes in the addins directory, which is the definition (configured) file of its core plug-in, which exists in the bin / sharpdevelop.base.dll file in the bin / sharpdevelop.base.dll file. There are many other plugins define in the Addin file in the Addins directory.
Analyze the code of SharpDevelop, first of all, we must figure out several basic concepts, these concepts have some differences in my previous expectations, I have found out my confusion after I go deep into the code. 1. The plug-in in the AddINtree Plug-in Tree SharpDevelop is organized into a plug-in tree structure, the structure of the tree is defined by the PATH (path) defined in the Extension (Path), similar to a directory structure of a file system. Each of the system is specified in the configuration file, which is hung on this plug-in tree via the PATH specified in Extension. Each plug-in can be accessed through the AddTReSingleton object to implement interaction between plugins. 2. ADIN Plugin In the concept of SharpDevelop, the plugin is a collection of multiple functional modules (not a functional module I think in the past). On the form of a file is an AddIN profile, the AddIN class is corresponding in the system. 3, EXTENSION Extension Point SharpDevelop is being hung in the AddInTree (plugin tree), and which location is specifically hanging from this plugin tree, it is specified by the PATH in the extension object of the plugin. In the Addin configuration file, it corresponds to
Extension
Path
= "/ SharpDevelop / Workbench / Ambiences"
>
<
Class
id
= ".NET"
Class
= "Icsharpcode.sharpDevelop.services.Netambience"
/>
Extension
>
Specifies the extension point path to / sharpdevelop / workbench / Ambiences, that is, in the plugin tree. 4, Codon This is something that is more unhealthy, the Chinese translation of the three authors written in SharpDevelop is translated into a codon, really a bad translation, can fight with the Handle (handle). There is also a translation called "Book" in the dictionary, I think this is not good, but it is a little more meaningful. (Here I was originally mistaken as "Code". In the comments, I said that this brother said that this translation is good. Now I think it is really good ^ o ^) According to my understanding of the code, the Codon's function is to describe (packaging) one Function module (a functional module corresponds to a Command class that implements a specific function). In order to facilitate access to the functional modules in each plug-in, Codon defines basic properties to various functions, named ID (identifier of function modules), name (function module type. Don't misunderstand, this name is Codon in the Addin file definition The name of the XML node, the id is the real name), where Name may be a class, a menuItem (menu item), PAD (panel), and more. Depending on the specific functional module, you can inherit the Codon definition of other properties, and ClassCodon, MenuItemcodon, PadCodon, etc., you can define yourself as needed to define other types of Codon as needed. In the Addin definition file, Codon corresponds to the content under the
<
Extension
Path
= "/ SharpDevelop / Workbench / Ambiences"
>
id = ".NET" Class = "Icsharpcode.sharpDevelop.services.Netambience" /> Extension > < 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 > The three menu items are defined in this extension, as well as the names, labels and class names of each menu item. The Codon here corresponds to the MenuCodon object in the system. 5, the command command is as mentioned above, Codon describes a functional module, and each function module is an ICommand implementation. The most basic Command is AbstractCommand, which corresponds to different Command according to the different Codon. For example, MenuItemCodon corresponds to MenuItemCommand, and more. 6. Some functions are used throughout the system, such as file access, resources, messages, and more. These functions are served as a basic function of the plugin system for the entire system, and we are called "service". For ease of access, these services are uniformly managed by ServiceManager. In fact, services are also a type of plug-in, their extension paths in / Workspace / Services in the directory tree. After understanding these basic concepts, you can take a look at SharpDevelop's code. From SRC / Main / Startup.cs, you will then be addIN.cs, addintree.cs, etc. Write two hours, take a break. And listen to the decomposition.