开发者

Is there a snippet for an auto-property in VB.NET?

开发者 https://www.devze.com 2023-02-02 22:25 出处:网络
In Visual Studio 2010, for VB.NET, the \"Prop开发者_如何学Certy\" + Tab + Tab inserts a full property implementation. Is there another snippet for inserting an autoproperty?Just put this in a file cal

In Visual Studio 2010, for VB.NET, the "Prop开发者_如何学Certy" + Tab + Tab inserts a full property implementation. Is there another snippet for inserting an autoproperty?


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>


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号