2

In Visual Studio 2010, for VB.NET, the "Property" + Tab + Tab inserts a full property implementation. Is there another snippet for inserting an autoproperty?

Chris
  • 2,959
  • 1
  • 30
  • 46

2 Answers2

3

Just put this in a file called C:\Users\\Documents\Visual Studio 2010\Code Snippets\Visual Basic\My Code Snippets\DefaultProperty.snippet and restart VS... or put it in that file but not in that dir, then in VS click Tools, Code Snippets Manager, and Select Visual Basic as the language... the click on the Import button. Select your new file, and then choose the top folder "My Snippets". Now in the IDE just type PropDefAuto and tab tab. Feel free to modify the file.

<?xml version="1.0" encoding="UTF-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
  <CodeSnippet Format="1.0.0">
    <Header>
      <Title>Define a Auto-Implemented Default Property</Title>
      <Author>Some Guy On SO</Author>
      <Description>Defines an Auto-Implemented default property or index property.</Description>
      <Keywords>
          <Keyword>PropAuto</Keyword>
      </Keywords>
      <Shortcut>PropDefAuto</Shortcut>
    </Header>
    <Snippet>
      <Imports>
        <Import>
          <Namespace>System</Namespace>
        </Import>
      </Imports>
      <Declarations>
        <Literal>
          <ID>propertyName</ID>
          <Type>
          </Type>
          <ToolTip>Rename to descriptive name for the property.</ToolTip>
          <Default>PropertyName</Default>
        </Literal>
        <Literal>
          <ID>indexType</ID>
          <Type>
          </Type>
          <ToolTip>Replace with the type of the index</ToolTip>
          <Default>Integer</Default>
        </Literal>
        <Literal>
          <ID>propertyType</ID>
          <Type>
          </Type>
          <ToolTip>Replace with the type returned by the property.</ToolTip>
          <Default>String</Default>
        </Literal>
        <Literal>
          <ID>IndexIsValid</ID>
          <Type>Boolean</Type>
          <ToolTip>Replace with an expression to test if index is valid.</ToolTip>
          <Default>True</Default>
        </Literal>
      </Declarations>
      <Code Language="VB" Kind="method decl"><![CDATA[Public Property $propertyName$ As $PropertyType$
      ]]></Code>
    </Snippet>
  </CodeSnippet>
</CodeSnippets>
CrazyDart
  • 3,803
  • 2
  • 23
  • 29
  • Errr, that was for VS 2010 BTW... if you want VS 2008, just find the snippit the same way in VS 2008 that does the property and modify... but dont overwrite... put your custom one in the My Snippits dir. – CrazyDart Jan 07 '11 at 23:51
  • Nice! Now I just have to figure out how to get it in my intellisense. :) – Chris Jan 08 '11 at 00:06
  • yah I noticed that didnt happen... in C# it just automatically happens... I know there is a way to tell it to refresh... good luck – CrazyDart Jan 08 '11 at 00:07
0

The closest you can currently get in VB is typing out

Property Name as string

You can find more information in this blog post by The Gu

sclarson
  • 4,362
  • 3
  • 32
  • 44