Visual Studio 2015 Implement Interface snippet not working

Category: visual studio lsextensibility

Question

John Fager (JFM) on Tue, 15 Sep 2015 12:19:49



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

In the past, this worked: http://codeimpossible.com/2010/11/29/Make-Implement-Interface-use-auto-properties/

With Visual Studio 2015, this snippet is ignored and the throw new NotImplement

By default:

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



What I want Implement Interface to script out:

public object MyProperty { get; set; }




Replies

Yanjin Xu - MSFT on Fri, 18 Sep 2015 08:57:28


Hi John,

For this VS behavior, I think you could give a feedback to Microsoft Visual Studio Connect Site, and check whether they have good workaround for you, Microsoft engineers will evaluate this seriously.

With regards,

Angie

John Fager (JFM) on Fri, 02 Oct 2015 00:55:09


Thanks Angie for the direction, but it really isn't an answer for us to run around from one Microsoft site to another with this stuff. 

I'm pretty sure that this is on topic here.

Marking this as answered will end up indexed on search engines for others looking for an answer, but it isn't answered.


I did post to the recommend board referencing this.

David Ziffer on Thu, 17 Mar 2016 03:28:45


Was there ever a solution to this? I was watching an MVVM tutorial on the web and the presenter implemented an interface using a snippet (typed almost too fast to follow him). Never having implemented an interface that way before, I simply copied his keystrokes over and over to no avail. Since I was new at this, I figured I was doing something wrong. Thanks.

John Fager (JFM) on Mon, 16 May 2016 16:52:52


Bump...

Jan Van der Haegen on Tue, 14 Jun 2016 12:42:53


Hey John!

The short answer to your question is: "no, it is not possible". Visual Studio 2015 uses Roslyn for it's refactoring, which means the snippets are no longer used when invoking the "Implement interface" refactoring command. Hence, you can change the snippets all you want, they aren't picked up by the current refactoring engine.

John Fager (JFM) on Thu, 25 Aug 2016 13:50:53


Unfortunate that this little gem is gone!

RhaXiel on Fri, 27 Jan 2017 06:32:40


Hello,

I'm using a find and replace macro like this as a workaround:

Find:
(\r|\n| |\t)+\{(\r|\n| |\t)+get(\r|\n| |\t)+\{(\r|\n| |\t)+throw(\r|\n| |\t)+new(\r|\n| |\t)+NotImplementedException\(\);(\r|\n| |\t)+\}(\r|\n| |\t)+set(\r|\n| |\t)+\{(\r|\n| |\t)+throw(\r|\n| |\t)+new(\r|\n| |\t)+NotImplementedException\(\);(\r|\n| |\t)+\}(\r|\n| |\t)+\}

replace:
 {get;set;}