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