8

I am trying to get Visual Studio 2015 (14.0) to use auto properties when implementing an interface using refactoring for C#.

I.e. I want this;

public object SomeProperty { get; set; }

as opposed to this;

public object SomeProperty
{
    get
    {
        throw new NotImplementedException();
    }
    set
    {
        throw new NotImplementedException();
    }
}

I have accomplished this in past versions of Visual Studio by editing the code snippet file (instructions here) but I cannot get this to work using Visual Studio 2015.

4
  • I also cannot do this. I have changed my propertyStub.snippet but its not registering the change. did you get this solved? Commented Jan 6, 2016 at 15:21
  • No, it looks as though there is no resolution as of yet. If I had the time I would probably make an extension for myself. Commented Jan 6, 2016 at 22:03
  • See this thread for more information connect.microsoft.com/VisualStudio/feedback/details/1857694/… Commented May 31, 2016 at 10:32
  • Thanks @labilbe. I think I found this a long time ago. Disappointing but hopefully there will be a workaround or implementation in the future. Commented May 31, 2016 at 11:34

2 Answers 2

5

Ok, so I stumbled upon the answer during my testing of VS2019 Preview (16.0).

In the main menu bar Tools --> Options --> Text Editor --> C# --> Advanced look for the option Implement Interface or Abstract Class under When generating properties choose prefer auto properties.

This results in the same outcome that snippets used to take care of pre VS2015.

Sign up to request clarification or add additional context in comments.

Comments

1

You can solve by editing the PropertyStub.snippet

Just go to C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC#\Snippets\1033\Refactoring open PropertyStub.snippet and edit:

$GetterAccessibility$ get 
{ 
    $end$throw new $Exception$(); 
}
$SetterAccessibility$ set 
{ 
    throw new $Exception$(); 
}

to

$GetterAccessibility$ get;
$SetterAccessibility$ set;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.