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.
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.
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;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With