angus
angus

Reputation: 690

Refactoring "Implement Interface" using auto properties VS2015

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.

Upvotes: 8

Views: 1058

Answers (2)

angus
angus

Reputation: 690

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.

Upvotes: 5

Mauro Sampietro
Mauro Sampietro

Reputation: 2814

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;

Upvotes: 1

Related Questions