Skip to content

Commit fea5ee5

Browse files
committed
moved XML comments topic to snippets section; expanded snippets topic and moved it down a node in toc
1 parent a5bbfbf commit fea5ee5

10 files changed

+244
-229
lines changed

.openpublishing.redirection.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
},
5858
{
5959
"source_path": "docs/csharp-ide/code-generation/generate-xml-documentation-comments.md",
60-
"redirect_url": "/visualstudio/ide/reference/generate-xml-documentation-comments-csharp",
60+
"redirect_url": "/visualstudio/ide/reference/generate-xml-documentation-comments",
6161
"redirect_document_id": false
6262
},
6363
{
@@ -1472,7 +1472,7 @@
14721472
},
14731473
{
14741474
"source_path": "docs/vb-ide/code-generation/generate-xml-documentation-comments.md",
1475-
"redirect_url": "/visualstudio/ide/reference/generate-xml-documentation-comments-vb",
1475+
"redirect_url": "/visualstudio/ide/reference/generate-xml-documentation-comments",
14761476
"redirect_document_id": false
14771477
},
14781478
{

docs/TOC.md

+5-6
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,11 @@
103103
##### [Save and Open Files with Encoding](ide/how-to-save-and-open-files-with-encoding.md)
104104
#### [Outlining](ide/outlining.md)
105105
#### [Generate and Fix Code](ide/code-generation-in-visual-studio.md)
106-
##### [Code Snippets](ide/code-snippets.md)
107-
###### Use Code Snippets
108-
####### [Visual C# Code Snippets](ide/visual-csharp-code-snippets.md)
109-
####### [Visual C++ Code Snippets](ide/visual-cpp-code-snippets.md)
106+
##### Code Snippets
107+
###### [Use Code Snippets](ide/code-snippets.md)
108+
####### [C# Code Snippets Reference](ide/visual-csharp-code-snippets.md)
109+
####### [C++ Code Snippets Reference](ide/visual-cpp-code-snippets.md)
110+
####### [Insert XML Comments](ide/reference/generate-xml-documentation-comments.md)
110111
####### [Use Surround-with Code Snippets](ide/how-to-use-surround-with-code-snippets.md)
111112
####### [Best Practices](ide/best-practices-for-using-code-snippets.md)
112113
###### Create Code Snippets
@@ -124,7 +125,6 @@
124125
####### [Generate constructor](ide/reference/generate-constructor-csharp.md)
125126
####### [Generate override](ide/reference/generate-override-csharp.md)
126127
####### [Generate Equals and GetHashCode method overrides](ide/reference/generate-overrides-csharp.md)
127-
####### [Generate XML documentation comments](ide/reference/generate-xml-documentation-comments-csharp.md)
128128
####### [Implement abstract class](ide/reference/implement-abstract-class-csharp.md)
129129
####### [Implement interface](ide/reference/implement-interface-csharp.md)
130130
####### [Introduce local variable](ide/reference/introduce-local-variable-csharp.md)
@@ -134,7 +134,6 @@
134134
####### [Generate Field/Property/Local](ide/reference/generate-field-property-local-vb.md)
135135
####### [Generate Constructor](ide/reference/generate-constructor-vb.md)
136136
####### [Generate Override](ide/reference/generate-override-vb.md)
137-
####### [Generate XML Documentation Comments](ide/reference/generate-xml-documentation-comments-vb.md)
138137
####### [Implement Abstract Class](ide/reference/implement-abstract-class-vb.md)
139138
####### [Implement Interface](ide/reference/implement-interface-vb.md)
140139
####### [Introduce Local Variable](ide/reference/introduce-local-variable-vb.md)

docs/ide/best-practices-for-using-code-snippets.md

+56-53
Original file line numberDiff line numberDiff line change
@@ -4,67 +4,70 @@ ms.custom: ""
44
ms.date: "11/04/2016"
55
ms.reviewer: ""
66
ms.suite: ""
7-
ms.technology:
8-
- "vs-ide-general"
7+
ms.technology: vs-ide-general
98
ms.tgt_pltfrm: ""
109
ms.topic: "article"
1110
helpviewer_keywords:
1211
- "code snippets, best practices"
1312
- "code snippets, security"
14-
ms.assetid: a293ec17-4dd7-4a99-8eeb-99f44a822a8b
15-
caps.latest.revision: 22
1613
author: "gewarren"
1714
ms.author: "gewarren"
1815
manager: ghogen
1916
ms.workload:
2017
- "multiple"
2118
---
22-
# Best Practices for Using Code Snippets
23-
The code in a code snippet shows only the most basic way to do something. For most applications, the code must be modified to suit the application.
24-
25-
## Handling Exceptions
26-
Typically, code snippet Try...Catch blocks catch and rethrow all exceptions. That may not be the right choice for your project. For each exception, there are several ways to respond. For examples, see [How to: Handle an Exception Using try/catch (C# Programming Guide)](/dotnet/csharp/programming-guide/exceptions/how-to-handle-an-exception-using-try-catch) and [Try...Catch...Finally Statement](/dotnet/visual-basic/language-reference/statements/try-catch-finally-statement).
27-
28-
## File Locations
29-
When you adapt file locations to your application, you should think about the following:
30-
31-
- Finding an accessible location. Users may not have access to the Program Files folder of the computer, so storing files with the application files may not work.
32-
33-
- Finding a secure location. Storing files in the root folder (C:\\) is not secure. For application data, we recommend the \Application Data folder. For individual user data, the application can create a file for each user in the \My Documents folder.
34-
35-
- Using a valid file name. You can use the <xref:System.Windows.Forms.OpenFileDialog> and <xref:System.Windows.Forms.SaveFileDialog> controls to reduce the likelihood of invalid file names. Be aware that between the time the user selects a file and the time your code manipulates the file, the file may be deleted. In addition, the user may not have permissions to write to the file.
36-
37-
## Security
38-
How secure a snippet is depends on where it is used in the source code and how it is modified once it is in the code. The following list contains a few of the areas that must be considered.
39-
40-
- File and database access
41-
42-
- Code access security
43-
44-
- Protecting resources (such as event logs, registry)
45-
46-
- Storing secrets
47-
48-
- Verifying inputs
49-
50-
- Passing data to scripting technologies
51-
52-
For more information, see [Securing Applications](../ide/securing-applications.md).
53-
54-
## Downloaded Code Snippets
55-
IntelliSense code snippets installed by Visual Studio are not in themselves a security hazard. However, they can create security risks in your application. Snippets downloaded from the Internet should be treated like any other downloaded content - with extreme caution.
56-
57-
- Download snippets only from sites you trust, and use up-to-date virus software.
58-
59-
- Open all downloaded snippet files in Notepad or the XML editor of Visual Studio and review them carefully before installing them. Look for the following issues:
60-
61-
- The snippet code could damage your system if you execute it. Read the source code carefully before running it.
62-
63-
- The Help URL block of the snippet file can contain URLs that execute a malicious script file or display an offensive Web site.
64-
65-
- The snippet may contain references that are added silently to your project and may be loaded from anywhere on your system. These references may have been downloaded to your computer from where you downloaded the snippet. The snippet may then make a call to a method in the reference that executes malicious code. To protect yourself against such an attack, review the Imports and References blocks of the snippet file.
66-
67-
## See Also
68-
[Visual Basic IntelliSense Code Snippets](/dotnet/visual-basic/developing-apps/using-ide/intellisense-code-snippets)
69-
[Securing Applications](../ide/securing-applications.md)
70-
[Code Snippets](../ide/code-snippets.md)
19+
# Best practices for using code snippets
20+
21+
The code in a code snippet shows only the most basic way to do something. For most applications, the code must be modified to suit the application.
22+
23+
## Handling exceptions
24+
25+
Typically, code snippet Try...Catch blocks catch and rethrow all exceptions. That may not be the right choice for your project. For each exception, there are several ways to respond. For examples, see [How to: Handle an Exception Using try/catch (C#)](/dotnet/csharp/programming-guide/exceptions/how-to-handle-an-exception-using-try-catch) and [Try...Catch...Finally Statement (Visual Basic)](/dotnet/visual-basic/language-reference/statements/try-catch-finally-statement).
26+
27+
## File locations
28+
29+
When you adapt file locations to your application, you should think about the following:
30+
31+
- Finding an accessible location. Users may not have access to the Program Files folder of the computer, so storing files with the application files may not work.
32+
33+
- Finding a secure location. Storing files in the root folder (*C:\\*) is not secure. For application data, we recommend the *Application Data* folder. For individual user data, the application can create a file for each user in the *Documents* folder.
34+
35+
- Using a valid file name. You can use the <xref:System.Windows.Forms.OpenFileDialog> and <xref:System.Windows.Forms.SaveFileDialog> controls to reduce the likelihood of invalid file names. Be aware that between the time the user selects a file and the time your code manipulates the file, the file may be deleted. In addition, the user may not have permissions to write to the file.
36+
37+
## Security
38+
39+
How secure a snippet is depends on where it is used in the source code and how it is modified once it is in the code. The following list contains a few of the areas that must be considered.
40+
41+
- File and database access
42+
43+
- Code access security
44+
45+
- Protecting resources (such as event logs, registry)
46+
47+
- Storing secrets
48+
49+
- Verifying inputs
50+
51+
- Passing data to scripting technologies
52+
53+
For more information, see [Securing Applications](../ide/securing-applications.md).
54+
55+
## Downloaded code snippets
56+
57+
IntelliSense code snippets installed by Visual Studio are not in themselves a security hazard. However, they can create security risks in your application. Snippets downloaded from the Internet should be treated like any other downloaded content - with extreme caution.
58+
59+
- Download snippets only from sites you trust, and use up-to-date virus software.
60+
61+
- Open all downloaded snippet files in Notepad or the XML editor of Visual Studio and review them carefully before installing them. Look for the following issues:
62+
63+
- The snippet code could damage your system if you execute it. Read the source code carefully before running it.
64+
65+
- The Help URL block of the snippet file can contain URLs that execute a malicious script file or display an offensive Web site.
66+
67+
- The snippet may contain references that are added silently to your project and may be loaded from anywhere on your system. These references may have been downloaded to your computer from where you downloaded the snippet. The snippet may then make a call to a method in the reference that executes malicious code. To protect yourself against such an attack, review the Imports and References blocks of the snippet file.
68+
69+
## See also
70+
71+
[Visual Basic IntelliSense Code Snippets](/dotnet/visual-basic/developing-apps/using-ide/intellisense-code-snippets)
72+
[Securing Applications](../ide/securing-applications.md)
73+
[Code Snippets](../ide/code-snippets.md)

docs/ide/code-snippets.md

+22-17
Original file line numberDiff line numberDiff line change
@@ -5,29 +5,40 @@ ms.date: "11/04/2016"
55
ms.reviewer: ""
66
ms.suite: ""
77
ms.technology: vs-ide-general
8-
ms.tgt_pltfrm: ""
98
ms.topic: "article"
109
f1_keywords:
1110
- "vs.ExpansionManagerImport"
1211
- "vs.codesnippetmanager"
13-
helpviewer_keywords:
14-
- "code snippets, replacement parameters"
15-
- "code snippets, surround with"
16-
- "replacement parameters"
17-
- "code snippets, expansion"
12+
helpviewer_keywords:
1813
- "surround with"
1914
- "code snippets"
2015
author: "gewarren"
2116
ms.author: "gewarren"
2217
manager: ghogen
18+
dev_langs:
19+
- CSharp
20+
- VB
21+
- CPP
2322
ms.workload:
2423
- "multiple"
2524
---
2625
# Code snippets
2726

28-
Code snippets are small blocks of reusable code that can be inserted in a code file using a context menu command or a combination of hotkeys. They typically contain commonly-used code blocks such as try-finally or if-else blocks, but they can be used to insert entire classes or methods.
27+
Code snippets are small blocks of reusable code that can be inserted in a code file using a context menu command or a combination of hotkeys. They typically contain commonly-used code blocks such as `try-finally` or `if-else` blocks, but they can be used to insert entire classes or methods.
2928

30-
## Expansion Snippets and Surround-With Snippets
29+
Code snippets are available for a multitude of programming languages, including C#, C++, Visual Basic, XML, and T-SQL, to name a few. To view all the available installed snippets for a language, open the **Code Snippets Manager** from the **Tools** menu in Visual Studio, and choose the language from the drop-down menu at the top.
30+
31+
![Code Snippets Manager dialog box](media/code-snippets-manager.png)
32+
33+
Code snippets can be accessed in the following general ways:
34+
35+
- On the menu bar, choose **Edit** > **IntelliSense** > **Insert Snippet...**
36+
37+
- From the right-click or context menu in the code editor, choose **Snippet** > **Insert Snippet...**
38+
39+
- From the keyboard, press **Ctrl**+**K**+**X**
40+
41+
## Expansion snippets and surround-with snippets
3142

3243
In Visual Studio there are two kinds of code snippet: expansion snippets, which are added at a specified insertion point and may replace a snippet shortcut, and surround-with snippets (C# and C++ only), which are added around a selected block of code.
3344

@@ -44,7 +55,7 @@ finally
4455
}
4556
```
4657

47-
You can insert this snippet by clicking **Insert Snippet** in the context menu of the code window, then **Visual C#**, then type `tryf`, and then press **Tab**, or you can type `tryf` and press **Tab** twice.
58+
You can insert this snippet by clicking **Insert Snippet** in the context menu of the code window, then **Visual C#**, then type `tryf`, and then press **Tab**. Or, you can type `tryf` and press **Tab** twice.
4859

4960
An example of a surround-with snippet: in C++ the shortcut `if` can be used either as an insertion snippet or as a surround-with snippet. If you select a line of code (for example `return FALSE;`), and then click **Surround With**, then **if**, the snippet is expanded around the line:
5061

@@ -55,11 +66,11 @@ if (true)
5566
}
5667
```
5768

58-
## Snippet Replacement Parameters
69+
## Snippet replacement parameters
5970

6071
Snippets can contain replacement parameters, which are placeholders that you must replace to fit the precise code you are writing. In the previous example `true` is a replacement parameter, which you would replace with the appropriate condition. The replacement you make is repeated for every instance of the same replacement parameter in the snippet.
6172

62-
For example, in Visual Basic there is a code snippet that inserts a property. Click **Insert Snippet** on the context menu of the code window, then **Code Patterns**, then **Properties, Procedures, Events**, then Define a property. The following code is inserted:
73+
For example, in Visual Basic there is a code snippet that inserts a property. Click **Insert Snippet** on the context menu of the code window, then **Code Patterns**, then **Properties, Procedures, Events**, then **Define a Property**. The following code is inserted:
6374

6475
```vb
6576
Private newPropertyValue As String
@@ -75,12 +86,6 @@ End Property
7586

7687
If you change `newPropertyValue` to `m_property`, then every instance of `newPropertyValue` is changed. If you change `String` to `Int` in the property declaration, then the value in the set method is also changed to `Int`.
7788

78-
## Code Snippet Manager
79-
80-
You can see all the code snippets that are currently installed, and their locations on disk, by choosing **Tools**, **Code Snippets Manager**. Snippets are displayed by language.
81-
82-
You can add and remove snippet directories with the **Add** and **Remove** buttons in the **Code Snippets Manager** dialog. To add individual code snippets, use the **Import** button.
83-
8489
## See also
8590

8691
[Walkthrough: Creating a Code Snippet](../ide/walkthrough-creating-a-code-snippet.md)
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,60 @@
11
---
2-
title: "How to: Use Surround-with Code Snippets | Microsoft Docs"
2+
title: "How to Use Surround with Code Snippets | Microsoft Docs"
33
ms.custom: ""
44
ms.date: "11/04/2016"
55
ms.reviewer: ""
66
ms.suite: ""
7-
ms.technology:
8-
- "vs-ide-general"
7+
ms.technology: vs-ide-general
98
ms.tgt_pltfrm: ""
109
ms.topic: "article"
1110
helpviewer_keywords:
12-
- "Surround-with snippets"
13-
- "snippets [C#], using Surround With"
14-
ms.assetid: 23e5288e-7897-417a-9ded-cf60dfc889ee
15-
caps.latest.revision: 18
11+
- "surround-with snippets"
12+
- "snippets [C#], surround with"
1613
author: "gewarren"
1714
ms.author: "gewarren"
1815
manager: ghogen
1916
ms.workload:
2017
- "multiple"
2118
---
22-
# How to: Use Surround-with Code Snippets
23-
The following procedures describe how to use surround-with code snippets. Surround-with code snippets are available three ways: through a keyboard shortcut, through the Edit menu, and through the context menu.
24-
25-
### To use surround-with code snippets through keyboard shortcut
26-
27-
1. In the Visual Studio IDE, open the file that you intend to edit.
28-
29-
2. In the Code Editor, select text to surround.
30-
31-
3. Type CTRL+K, CTRL+S.
32-
33-
4. Select the code snippet from the code snippet list using the mouse, or by typing the name of the code snippet and pressing TAB or ENTER.
34-
35-
### To use surround-with code snippets through the Edit menu
36-
37-
1. In the Visual Studio IDE, open the file that you intend to edit.
38-
39-
2. In the Code Editor, select text to surround.
40-
41-
3. From the **Edit** menu, select **IntelliSense** and then select the **Surround With** command.
42-
43-
4. Select the code snippet from the code snippet inserter and then press TAB or ENTER.
44-
45-
Alternatively, you can type the name of the code snippet, and then press TAB or ENTER.
46-
47-
### To use surround-with code snippets through the context menu
48-
49-
1. In the Visual Studio IDE, open the file that you intend to edit.
50-
51-
2. In the Code Editor, select text to surround.
52-
53-
3. Right-click the selected text and then select the **Surround With** command from the context menu.
54-
55-
4. Select the code snippet from the code snippet inserter and then press TAB or ENTER.
56-
57-
Alternatively, you can type the name of the code snippet, and then press TAB or ENTER.
58-
59-
## See Also
60-
[Visual C# Code Snippets](../ide/visual-csharp-code-snippets.md)
61-
[Code Snippet Picker](../ide/reference/code-snippet-picker.md)
19+
# How to: Use surround-with code snippets
20+
21+
The following procedures describe how to use surround-with code snippets. Surround-with code snippets are available three ways: through a keyboard shortcut, through the **Edit** menu, and through the context menu.
22+
23+
## To use surround-with code snippets through keyboard shortcut
24+
25+
1. In the Visual Studio IDE, open the file that you intend to edit.
26+
27+
1. In the Code Editor, select text to surround.
28+
29+
1. Type **Ctrl**+**K**, **Ctrl**+**S**.
30+
31+
1. Select the code snippet from the code snippet list using the mouse, or by typing the name of the code snippet and pressing **Tab** or **Enter**.
32+
33+
## To use surround-with code snippets through the Edit menu
34+
35+
1. In the Visual Studio IDE, open the file that you intend to edit.
36+
37+
1. In the Code Editor, select text to surround.
38+
39+
1. From the **Edit** menu, select **IntelliSense** and then select the **Surround With** command.
40+
41+
1. Select the code snippet from the code snippet inserter and then press **Tab** or **Enter**.
42+
43+
Alternatively, you can type the name of the code snippet, and then press **Tab** or **Enter**.
44+
45+
## To use surround-with code snippets through the context menu
46+
47+
1. In the Visual Studio IDE, open the file that you intend to edit.
48+
49+
1. In the Code Editor, select text to surround.
50+
51+
1. Right-click the selected text and then select the **Surround With** command from the context menu.
52+
53+
1. Select the code snippet from the code snippet inserter and then press **Tab** or **Enter**.
54+
55+
Alternatively, you can type the name of the code snippet, and then press **Tab** or **Enter**.
56+
57+
## See also
58+
59+
[Visual C# Code Snippets](../ide/visual-csharp-code-snippets.md)
60+
[Code Snippet Picker](../ide/reference/code-snippet-picker.md)
14 KB
Loading

0 commit comments

Comments
 (0)