Customizing code snippet in Visual Studio

Source: Internet
Author: User
Tags cdata

As the strongest IDE in the universe, Visual Studio has powerful code editing, compiling, debugging, and deployment capabilities.

Writing code in Visual Studio is very handy, with good code hinting and coding snippet features, so that the program ape in the process of writing code, save time and effort and worry.

Using the Code snippet feature in Visual Studio, you can quickly generate code blocks and support multiple language types by simply entering a small number of strings and combining the TAB key.

For the C # language, the default code snippet includes:
Cw–console.writeline

Even though Visual Studio provides us with such a rich code snippets, it is still possible that we will not be able to meet our needs.

Program apes often need to create methods during their work, but each time you create a method in Visual Studio, access modifiers, return value types, method names, parameters, curly braces ... All need to be manually knocked, as a lazy program ape, this is definitely not what we want, with the universe's strongest IDE, we just need a few simple steps to customize the code snippet we want.

Study the code snippet for the For loop first

<?xml version= "1.0" encoding= "Utf-8"?> <codesnippets xmlns= "http://schemas.microsoft.com/VisualStudio/ 2005/codesnippet "> <codesnippet format=" 1.0.0 "> <Header> <title>for</title
            > <Shortcut>for</Shortcut> <description>for Loop Code Snippets </Description> <author>microsoft corporation</author> <SnippetTypes> <snippettype >Expansion</SnippetType> <SnippetType>SurroundsWith</SnippetType> &LT;/SN ippettypes> </Header> <Snippet> <Declarations> <litera
                    L> <ID>index</ID> <Default>i</Default>
                    <ToolTip> Index </ToolTip> </Literal> <Literal>
         <ID>max</ID>           <Default>length</Default> <ToolTip> max length </ToolTip> & lt;/literal> </Declarations> <code language= "CSharp" ><! 
            [Cdata[for (int $index $ = 0; $index $ < $MAX $; $index $++) {$selected $ $end $}]]>
 </Code> </Snippet> </CodeSnippet> </CodeSnippets>

The

Writes the custom code snippet according to the format of the code snippet file.

<?xml version= "1.0" encoding= "Utf-8"?> <codesnippets xmlns= "http://schemas.microsoft.com/VisualStudio/ 2005/codesnippet "> <codesnippet format=" 1.0.0 "> <Header> <title>vfunc</tit
            le> <Shortcut>vfunc</Shortcut> <Description> Code Snippets for methods </Description> <author>william chen</author> <SnippetTypes> <snippettype>expan sion</snippettype> </SnippetTypes> </Header> <Snippet> &lt
                    ;D eclarations> <literal editable= "true" > <ID>permission</ID>
                <ToolTip> access Control </ToolTip> <Default>public</Default> </Literal> <literal editable= "true" > <id>returnvaluetype</id&
                    Gt <tooltip> Return value types </ToolTip> <Default>void</Default> </Literal> <literal editable= "true" > <ID>methodname</ID> <toolt
            Ip> method name </ToolTip> <Default>Method</Default> </Literal> </Declarations> <code language= "CSharp" ><! [cdata[$permission $ $returnvaluetype $ $methodname $ () {$end $}]]> </Code> &L
 T;/snippet> </CodeSnippet> </CodeSnippets>

Save the above to a file with the suffix. Snippet, shortcut key ctrl+k,ctrl+b, enter code Snippet Manager, import file, done.

In the future when writing code, you need to create a new method, just type Vfunc, and then press the TAB key can be easily done.

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.