Attention: We are retiring the ASP.NET Community Blogs. Learn more >

VS2005 Code Snippets

In VS2005, Code Snippets can be found by right-clicking in your code page and choosing Insert Snippet.  Also, all of the snippets have a shortcut.  Type the shortcut and then press tab and the code snippet will be automatically inserted.  For instance to automatically insert a code snippet for a for each loop type "foreach" and then press tab.

All of the code snippets can be found here:
VB: C:\Program Files\Microsoft Visual Studio 8\VB\Snippets
C#: C:\Program Files\Microsoft Visual Studio 8\VC#\Snippets
and then you can use the manager to register your own code snippet folder and create your own.
 
Here's one that I use for inserting a public property
 
<?xml version="1.0" encoding="UTF-8"?>
<CodeSnippets xmlns="
http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
  <CodeSnippet Format="1.0.0">
    <Header>
      <Title>Insert Property String</Title>
      <Author>Jeff Widmer</Author>
      <Description>Insert Property String</Description>
      <Shortcut>vbpropstring</Shortcut>
      <HelpUrl></HelpUrl>
    </Header>
    <Snippet>
  <Imports>
   <Import>
    <Namespace>System</Namespace>
   </Import>
  </Imports>
  <Declarations>
        <Literal>
          <ID>PropertyName</ID>
          <Type>String</Type>
          <ToolTip>Replace with property name.</ToolTip>
          <Default>X</Default>
        </Literal>
        <Literal>
          <ID>PropertyType</ID>
          <Type>
          </Type>
          <ToolTip>Replace with the property type.</ToolTip>
          <Default>String</Default>
        </Literal>
      </Declarations>
      <Code Language="VB" Kind="method decl">
    <![CDATA[Private _$PropertyName$ As $PropertyType$ = String.Empty
Public Property $PropertyName$() As $PropertyType$
    Get
        Return _$PropertyName$
    End Get
    Set(ByVal value As $PropertyType$)
        _$PropertyName$ = value
    End Set
End Property]]></Code>
    </Snippet>
  </CodeSnippet>
</CodeSnippets>

2 Comments

Comments have been disabled for this content.