在VB.NET中是否有自动属性的片段?

时间:2011-01-07 23:25:36

标签: vb.net visual-studio-2010 code-snippets automatic-properties

在Visual Studio 2010中,对于VB.NET,“Property”+ Tab + Tab会插入完整的属性实现。是否有另一个用于插入autoproperty的片段?

2 个答案:

答案 0 :(得分:2)

只需将其放在名为C:\ Users \\ Documents \ Visual Studio 2010 \ Code Snippets \ Visual Basic \ My Code Snippets \ DefaultProperty.snippet的文件中,然后重新启动VS ...或将其放在该文件中但不在那个目录,然后在VS中单击工具,代码片段管理器,并选择Visual Basic作为语言...单击导入按钮。选择新文件,然后选择顶部文件夹“My Snippets”。现在在IDE中只需输入PropDefAuto和tab选项卡。随意修改文件。

<?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>

答案 1 :(得分:0)

目前在VB中最接近的是键入

Property Name as string

您可以在The Gu

this blog帖子中找到更多信息
相关问题