Visual Studio 2017 propfull 代码段但带有 .this

Visual Studio 2017 propfull snippet but with .this

你好,我在 VS 中经常使用 propfull 代码段,但我每次都必须添加 .this,因为快捷方式不包含它。知道我在哪里可以找到这样做的片段(对于没有 resharper 的 VS 2017)。我进行了搜索,但我能找到的最好的是一个 resharper 版本,但它对我不起作用。抱歉,如果这是在某处发布的,但我找不到答案。

示例:

正常propfull:

    private int myVar;

    public int MyProperty
    {
        get { return myVar; }
        set { myVar = value; }
    }

所需的 propfull:

    private int myVar;

    public int MyProperty
    {
        get { return this.myVar; }
        set { this.myVar = value; }
    }

您可以使用在 Visual Studio 中找到的代码段管理器来执行此操作,方法是在“工具”->“代码段管理器”下...

我以 Microsoft 代码段的 propfull 实现为例,只是对其稍作更改,以便将其添加到属性前面,如下所示:

<?xml version="1.0" encoding="utf-8" ?>
<CodeSnippets  xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
  <CodeSnippet Format="1.0.0">
    <Header>
      <Title>propfull with this</Title>
      <Shortcut>thispropfull</Shortcut>
      <Description>Code snippet for property and backing field</Description>
      <Author>Icepickle</Author>
      <SnippetTypes>
        <SnippetType>Expansion</SnippetType>
      </SnippetTypes>
    </Header>
    <Snippet>
      <Declarations>
        <Literal>
          <ID>type</ID>
          <ToolTip>Property type</ToolTip>
          <Default>int</Default>
        </Literal>
        <Literal>
          <ID>property</ID>
          <ToolTip>Property name</ToolTip>
          <Default>MyProperty</Default>
        </Literal>
        <Literal>
          <ID>field</ID>
          <ToolTip>The variable backing this property</ToolTip>
          <Default>myVar</Default>
        </Literal>
      </Declarations>
      <Code Language="csharp"><![CDATA[private $type$ $field$;

  public $type$ $property$
  {
    get { return this.$field$;}
    set { this.$field$ = value;}
  }
  $end$]]>
      </Code>
    </Snippet>
  </CodeSnippet>
</CodeSnippets>

您可以将此文件保存为您自己的代码片段(扩展名为 .snippet),然后使用导入按钮添加您自己的代码片段。然后你可以编写快捷方式thispropfull,它会创建所需的代码段