Editing Refactoring snippet for C# in Visual Studio 2015, doesn't change the refactoring behaviour?

半腔热情 提交于 2019-12-10 17:13:07

问题


I want to change the typical property generation from outputting this:

set
{
    amountOfDogesValue = value;
}

to outputting something like this:

set
{
    if (value > 0)
        amountOfDogesValue = value;
    else
        throw new System.ArgumentException("Parameter cannot be smaller than 0", "DogesAmount");
}

(but) with some elements that don't compile, in the if clause and throw line, so I can never ever forget to edit them.

I use Visual Studio 2015 and have edited C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC#\Snippets\1033\Refactoring\EncapsulateField.snippet

and restarted MVS, and rebooted the pc.

Yet somehow it still refactors exactly the same way as before.

Here's my code for EncapsulateField.snippet

<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets  xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
    <CodeSnippet Format="1.0.0">
        <Header>
            <Title>Encapsulate Field</Title>
            <Description>Refactoring snippet for Encapsulate field</Description>
            <Author>Microsoft Corporation</Author>
            <SnippetTypes>
                <SnippetType>Refactoring</SnippetType>
            </SnippetTypes>
        </Header>
        <Snippet>
            <Declarations>
                <Literal Editable="true">
                    <ID>modifier</ID>
                    <Default>public</Default>
                </Literal>
                <Literal Editable="false">
                    <ID>type</ID>
                    <Default>type</Default>
                </Literal>
                <Literal Editable="false">
                    <ID>name</ID>
                    <Default>name</Default>
                </Literal>
                <Literal Editable="false">
                    <ID>field</ID>
                    <Default>field</Default>
                </Literal>
            </Declarations>
            <Code Language="csharp">
                <![CDATA[

$modifier$ $type$ $name$
{
  get { return $field$; }
  set 
  { 
    if (value x= xm)
      $field$ = value;
    else
      throw new System.ArgumentException("Parameter cannot be "+, "$field$");
  }
}]]>
            </Code>
        </Snippet>
    </CodeSnippet>
</CodeSnippets>

(The x= xm is to remind me to change to the contextually correct operand and the +, is to remind me to edit the string before it.)

来源:https://stackoverflow.com/questions/41299349/editing-refactoring-snippet-for-c-sharp-in-visual-studio-2015-doesnt-change-th

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!