Code Snippets

Visual Studio provides a feature called code snippets. You can use code snippets to type a short alias, and then expand it into a common programming construct. IFS provides a number of code snippets to use when developing in the Applications Forms framework. These are installed with the development environment for client development.

Code snippets can commonly be used in two ways. Firstly, they can be inserted at the given position in the source. Secondly, many snippets support "surround-with", which places selected source within the code snippet. The later is used when existing code should be re-factored in some way. E.g. when a block of code needs to be surrounded by an if statement, a for loop or put into a #region. Using surround-with is quicker than normal copy paste and it automatically assists with the syntax.

Contents

Insert Code Snippets

The following procedures describe how to use code snippets. Code snippets are available in five ways: through a keyboard shortcut, through IntelliSense auto-completion, through the IntelliSense complete word list, through the Edit menu, and through the context menu.

Figure1: Insert a Window Actions Template.

Insert code snippet from the Edit menu

  1. In the Code Editor in Visual Studio, place the cursor where you would like to insert the code snippet.
  2. From the Edit menu, select IntelliSense and then select the Insert Snippet command.
  3. Select the code snippet from the code snippet inserter.

Insert code snippet from the context menu

  1. In the Code Editor in Visual Studio, place the cursor where you would like to insert the code snippet.
  2. Right-click the cursor and then select the Insert Snippet command from the context menu.
  3. Select the code snippet from the code snippet inserter.

Insert code snippet using keyboard shortcut

  1. In the Code Editor in Visual Studio, place the cursor where you would like to insert the code snippet.
  2. Type CTRL+K, CTRL+X.
  3. Select the code snippet from the code snippet inserter.

Insert code snippet using IntelliSense auto-completion

  1. In the Code Editor in Visual Studio, place the cursor where you would like to insert the code snippet.
  2. Type the shortcut for the code snippet that you want to add to your code.
  3. Type TAB, TAB to insert the code snippet.

Insert code snippet using IntelliSense Complete Word list

  1. In the Code Editor in Visual Studio, place the cursor where you would like to insert the code snippet.
  2. Begin typing the shortcut for the code snippet that you want to add to your code. If automatic completion is turned on, then the IntelliSense complete word list will be displayed. If it does not appear, then press CTRL+SPACE to activate it.
  3. Select the code snippet from the complete word list.
  4. Type TAB, TAB to invoke the code snippet.

Surround-with Code Snippets

The following procedures describe how to use code snippets to surround selected code. Surround with code snippets are available in three ways: through a keyboard shortcut, through the Edit menu, and through the context menu.

Figure 2: Places a selection of code into a SalContext.

Surround code with snippet using keyboard shortcut

  1. In the Code Editor in Visual Studio, select text to surround.
  2. Type CTRL+K, CTRL+S.
  3. Select the code snippet from the code snippet list.

Surround code with snippet using the Edit menu

  1. In the Code Editor in Visual Studio, select text to surround.
  2. From the Edit menu, select IntelliSense and then select the Surround With command.
  3. Select the code snippet from the code snippet inserter.

Surround code with snippet using the context menu

  1. In the Code Editor in Visual Studio, select text to surround.
  2. Right-click the selected text and then select the Surround With command from the context menu.
  3. Select the code snippet from the code snippet inserter.