Online resources fragmented, mainly under the collation.
Finishing is the main core content, the full content can be seen in the following annotated source link.
What is a code snippet
The function of code snippet (Snippet) in VS2008
InIn VS2008, it providesCode Snippet (Snippet) The function.
What is a code snippet? Even though you're not familiar with the word, it's very likely-You've already used it unconsciously.
Example:
When we are writing a selection branch (If statement) or a loop branch (for statement), do you want to completely manually knock out every character? Of course not so stupid, we just enter "if" and then double-click the tab key,if the classic structure of the statement is leap off. In this case, we just write the conditions in the green box.
See this, you will be loudly exclaimed: This I have already used Ah! Yes, this is the code snippet, not only supports if, but also supports a variety of C # Common statements such as For,do,switch. There are several ways to insert code snippets:1. Right-click in the Edit area and select Insert Snippet . 2. Shortcut key ctrl+k,x
Similarly, we can select some of the written statements, and then insert the "outer code snippet ", then the selected statement will be surrounded by the selected code snippet.
How to add your own code to a code snippet
"VS2008 Skills (1)"
How do I add code snippets to my code?
In the coding process, there are often some common code results will be reused, is there a way to embed the code into the VS IDE?
Workaround: No problem at all, using the snippet file can be a good solution to this problem. Open \program Files\Microsoft Visual Studio 8\vc#\snippets\2052\visual C # There are many vs snippet files that you just need to copy, Then change it to your own code snippet.
See illustration:
The code is as follows:
1<?xml version= "1.0" encoding= "Utf-8"?>
2<codesnippets xmlns= "Http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet" >
3 <codesnippet format= "1.0.0" >
4 <Header>
5 <Title>try-catch-finall</Title>
6 <Shortcut>trycf</Shortcut>
7 <description>try Catch Finall code snippet </Description>
8 <Author> Chu Feng </Author>
9 <SnippetTypes>
Ten <SnippetType>Expansion</SnippetType>
<SnippetType>SurroundsWith</SnippetType>
</SnippetTypes>
</Header>
<Snippet>
<code language= "CSharp" >
<! [Cdata[try
17{
$end $
19}
catch (Exception exp)
{
22
23}
Finally
{
26
27}
]]>
</Code>
</Snippet>
</CodeSnippet>
32</codesnippets>
-
Use:
such as: Find the alias of the code snippet you set, enter the return, and then enter the TAB key, you can automatically generate the following code:
A better Code Snippet editor
VS Code Snippets (snippet) authoring tool--snippet Editor
Snippet Editor is a tool for editing vs code snippets, and it is free and practical in the same kind of tool.
Official page: http://snippeteditor.codeplex.com/
Reference reference:
Features of code Snippets (Snippet) in VS2008
VS2008 Tips (1)
VS code fragment (snippet) authoring tool--snippet Editor
VS2008 Code Snippet (Snippet) and code snippet editing