Sharpdevelop source code analysis (1. Sequence + basic concepts)

Source: Internet
Author: User

Collation

I recently started to learn about. NET and met a good open-source ide sharpdevelop. This development tool is developed using C #. One thing that attracts me is that it adopts plug-in technology similar to eclipse to implement the entire system. This plug-in system is my most interesting place, so I started to study a piece of code. After this article, I will write down my research experiences one after another. Internet access in Internet cafes is inconvenient, so it may take a long time.

I. Basic Concepts

First, let's have a more emotional understanding of sharpdevelop. You can download it from here to its executable program and code package http://www.icsharpcode.com/, the installation of nonsense will not say, first run a look. Does it feel like? However, the current version is 1.0.0.1550 and needs to be improved in many aspects. The three authors of sharpdevelop wrote a book about the code and system structure. You can refer to this book. However, I still have a lot of questions about the code and system structure.

Then, let me explain what plug-ins are and why plug-in systems are used. In our previous systems, after developers compile and release the system, the system cannot be changed or expanded. To expand a function, you must modify the code and re-compile and release it. This makes us very inconvenient. There are many solutions, such as configuration. In the solution, plug-ins are a better solution. Everyone must know Photoshop and Winamp. They all have the concept of "plug-ins", allowing other developers to compile extended functions (such as various filters in Photoshop) based on the Interface predefined by the system ). The so-called plug-in is the extended function module of the system. This module appears in the form of an independent file, which is relatively independent from the system. During the system design period, you do not know the specific functions of the plug-in. Instead, you only need to leave a predetermined interface for the plug-in the system. When the system starts, find the plug-in based on the plug-in configuration, mount the plug-in to the system based on the predefined interface.

What are the advantages of this method? First, the scalability of the system is greatly enhanced. If we need to expand the system after the system is released, we don't have to re-compile it. We only need to modify the plug-in. Secondly, it is advantageous for team development. Because each function module is represented in the system in the form of plug-ins, the daily structure of the system is very simple, the build of the entire system will not fail due to a module error. The failure is only a plug-in.

Photoshop and Winamp plug-in systems are relatively simple. They first implement a basic system, and then mount other extended functional plug-ins on the basis of this system. The sharpdevelop plug-in system is more powerful. The basis of its entire system is only a plug-in management system, and all the interfaces and functions you see are mounted in the form of plug-ins. In such a plug-in system, we can build a variety of different systems without modifying the basic system.

Now let's take a look at its plug-in system. In the installation directory of sharpdevelop, sharpdevelop.exe and sharpdevelop. Core. dll under the bindirectory are the basic plug-in systems of this system. In the addins directory, there are two files with the suffix addin, one of which is sharpdevelopcore. addin is the definition (configuration) file of its core plug-in. Each function module defined in addin exists in Bin/sharpdevelop. base. in the DLL file, there are also many other plug-ins defined in The addin file under the addins directory.

To analyze the sharpdevelop code, first of all, we need to clarify several basic concepts. These concepts are different from my previous expectations. After I dive into the code, I find my confusion.

1. addintree plug-in tree
The plug-ins in sharpdevelop are organized into a plug-in tree structure defined by the path defined in extension (extension point), similar to the directory structure of a file system. In the system, each plug-in has specified extension in the configuration file and is mounted to this plug-in tree through the path specified in extension. In the system, you can access each plug-in through the addtreesingleton object to implement interaction between plug-ins.

2. addin plug-in
In the sharpdevelop concept, a plug-in is a collection of Multiple Functional Modules (instead of a functional module I previously thought ). The file is an addin configuration file, which corresponds to the addin class in the system.

3. Extension
Each plug-in sharpdevelop will be mounted to the addintree. The location of the plug-in tree to which the plug-in is attached is specified by the path in the extension object of the plug-in. In The addin configuration file, it corresponds to <extension>. For example, the configuration of the function module below

<Extension path = "/sharpdevelop/workbench/ambiences">
<Class id = ". Net" class = "icsharpcode. sharpdevelop. Services. netambience"/>
</Extension>

The extension point path is/sharpdevelop/workbench/ambiences, that is, the position in the plug-in tree.

4. codon
This is a hard-to-understand thing. It is translatedCodonsIt's really a bad translation. It can work with handle. There is also a translation in the dictionary called "base code". I think this is not good, but it is a little more interesting. (Here I mistakenly wrote it as a "code subaccount", and one of my comments said this translation is good, and now I think it seems really good ^ o ^)
According to my understanding of the Code, the function of codon is to describe (Package) a function module (a function module corresponds to a command class that implements specific functions ). To facilitate access to function modules in various plug-ins, codon defines basic attributes for various functions, namely, ID (ID of the function module) and name (type of the function module. Don't get it wrong. This name is the name of the codon XML node in the definition of the addin file, and the ID is the real name. The name may be a class or menuitem) and pad (panel. Based on the specific functional modules, You can inherit other attributes defined by codon. sharpdevelop defines classcodon, menuitemcodon, padcodon, and so on. You can define other types of codon as needed. 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...> A codon is defined internally. <Class...> Indicates that the codon is a class, and then defines the ID of the codon and the class name icsharpcode. sharpdevelop. Services. netambience that implements the codon. During runtime, the corresponding class will be found and created through reflection, which cannot be implemented in previous languages.

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 names, labels, and class names of each menu item. The codon corresponds to the menucodon object in the system.

5. Command command
As mentioned above, codon describes a function module, and each function module is an icommand implementation. The most basic command is abstractcommand, which corresponds to different codon commands. For example, menuitemcodon corresponds to menuitemcommand.

6. Service
In the plug-in system, some functions are used by the entire system, such as file access, resources, and messages. These functions serve the entire system as a basic function of the plug-in system. We just call them "services. To facilitate access, these services are all managed through servicemanager. In fact, services are also a type of plug-ins. Their extension path is in/workspace/services in the directory tree.

After understanding these basic concepts, you can look at the sharpdevelop code. See src/main/startup. CS, followed by addin. CS, addintree. CS, and so on.

I have been writing for two hours. Take a break. In addition, the next loop is decomposed.

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.