Tips for Visual Studio: custom code snippets

Source: Internet
Author: User

Click Visual Studio and you will find a code snippet menu:650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/21155020a-0.jpg "border =" 0 "align =" absmiddle "/>


Click it to find that it is a common code snippet Tab shortcut) Manager:650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/2115504G1-1.jpg "border =" 0 "align =" absmiddle "/>


Open the above folder path:650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/2115502932-2.jpg "border =" 0 "align =" absmiddle "/>


Experience or intuition shows that to customize code snippets, you only need to copy the file, change the name and parameters, and then import the file:


The following is an example of the MAction class:


I copied if. snippet and renamed it maction. snippet. Then I opened it with vs and found it was xml:<? Xml version = "1.0" encoding = "UTF-8"?> <CodeSnippets xmlns = "http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet"> <CodeSnippet Format = "1.0.0"> <Header> <Title> if </Title> <Shortcut> if </Shortcut> <Description> if statement </Description> <Author> Microsoft Corporation </Author> <SnippetTypes> <SnippetType> Expansion </SnippetType> <SnippetType> SurroundsWith </SnippetType> </SnippetTypes> </ header> <Snippet> <Declarations> <Literal> <ID> expression </ID> <Tool Tip> expression to be calculated </ToolTip> <Default> true </Default> </Literal> </Declarations> <Code Language = "csharp"> <! [CDATA [if ($ expression $) {$ selected $ end $}]> </Code> </Snippet> </CodeSnippet> </CodeSnippets>

After scanning, we found that this xml is very simple. We only need to modify the first few letters of the Shortcut knock), and change the content in the Code to our own. Of course, the description and parameters and expressions are required, you can also change it as needed:

650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/2115501P9-3.jpg "border =" 0 "align =" absmiddle "/>

OK. After the modification, we thought we had to import the data, but we found that the replication in the default directory takes effect directly.


Test and press ma directly:650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/2115503932-4.jpg "border =" 0 "align =" absmiddle "/>

The code snippet prompt is displayed. Double-click the Tab button and the code snippet is displayed:

Using (MAction action = new MAction (the cursor is located here )){}


Isn't it easy to say that using this method, you can make common code snippets into two letter shortcuts Tab), which can improve the normal coding speed.


Related Article

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.