"Code snippet" let efficiency fly for a while

Source: Internet
Author: User

Introduction

A lot of code snippets have been pre-defined in VS, such as defining the prop of attributes, creating class classes, and so on, which is very convenient for us to develop. But it doesn't meet our 100% requirements, and sometimes it's very necessary to customize our own code snippets.

Learn about the code snippets

There is enough information on MSDN for us to learn how to create a code snippet.

1. First put the data in the default code snippet, all of the predefined code snippets. Portal

2. Then put some basic knowledge of the code snippet, which describes the schema elements of the code snippet. Portal

3. Finally, the code snippet walkthrough, follow the steps inside, and you'll soon learn how to write your own code snippet. Portal

Writing custom Code Snippets

In fact, the code snippet is an XML file, and you can start writing a new XML item in VS. to cope with the troublesome attribute definitions in WPF development, I wrote the code snippet < auto-notification properties > code as follows

<?XML version= "1.0" encoding= "Utf-8"?><CodeSnippetsxmlns= "Http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">  <CodeSnippetFormat= "1.0.0">    <Header>      <Title>Nisp</Title>      <Author>Caizl</Author>      <Description>Generate automatic Notification properties</Description>      <Shortcut>Nisp</Shortcut>    </Header>    <Snippet>      <Declarations>        <Literal>          <ID>Type</ID>          <ToolTip>Type</ToolTip>          <Default>String</Default>        </Literal>        <Literal>          <ID>Name</ID>          <ToolTip>Internal variables</ToolTip>          <Default>Name</Default>        </Literal>        <Literal>          <ID>Name</ID>          <ToolTip>Property name</ToolTip>          <Default>Name</Default>        </Literal>      </Declarations>      <CodeLanguage= "CSharp">        <! [Cdata[private $Type $ _$name$;           Public $Type $ $Name $ {get{return _$name$;}                set {if (Equals (value, _$name$)) return;                _$name$ = value;            raisePropertyChanged (() = $Name $); }         }]]>      </Code>    </Snippet>  </CodeSnippet></CodeSnippets>

Working with Code Snippets

In the VS Toolbar-code Snippet Manager, under the My Code Snippets folder, select Import the code snippet written above, then complete the setup. Below, directly in the code file to knock out the NISP, press the TAB key will see our code, simple and practical.

Summary

Reasonable use of code snippets can improve a lot of development efficiency. In addition, there is an artifact can also improve our efficiency, that is Resharper, is simply a variety of gods operating a variety of convenience ah. Finally, can not be VS2012 is not smart enough to knock a "(" unexpectedly can't automatically come out "), You know how hard it is for me to knock. However, the VS2015 preview version has improved, at least it can come out ")" .

"Code snippet" let efficiency fly for a while

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.