Tips for Visual Studio: custom code snippets

Source: Internet
Author: User
Click Visual Studio and you will find a code snippet menu: 

 

Click it and you will find that it is the manager of common code snippets (Tab shortcuts:

 

Open the above folder path:

 

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 the xml is very simple. We only need to modify the cut (the first few letters) and the content in the Code into our own. Of course, the description and parameters and expressions, you can also change it as needed:

 

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: 

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, we can make common code snippets into two letter shortcuts (tabs), which can improve the coding speed at ordinary times.

I don't know how many people have used this VS tips, but I know that I have used them to raise my objections. If I don't know or don't use them, I can recommend them.

 

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.