Embed Interface Refactoring Using Auto VS2015 Properties

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

those. I want it;

public object SomeProperty { get; set; } 

in contrast to this;

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

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

+6
source share
2 answers

So, I came across an answer while testing VS2019 Preview (16.0).

In the main menu menu " Tools --> Options --> Text Editor --> C# --> Advanced Search". " Implement Interface or Abstract Class When generating properties select" prefer auto properties .

This leads to the same result as the fragments that were used for preliminary testing of VS2015.

0
source

You can decide by editing 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; 
+1
source

All Articles