The functionality to extract an interface from a class (C#) seems to change in VS 2017. How can I do that in Visual Studio 2017.
5 Answers
Right-click the class name and select "Quick Actions and Refactorings..." and then select "Extract interface..."
Note that you can also click on the class name and press Ctrl+. to bring up the same context menu.
-
-
3For some reason, I'm not seeing this behavior. I used it all the time in 2015, but now all I see is "Generate overrides..."– user2836056Oct 31, 2017 at 20:51
-
5Huh. Looks like I have to add a public property or method to a class before I can interface it... I guess that makes sense... but I don't like it.– user2836056Oct 31, 2017 at 21:02
With ReSharper installed, right click the class name: Refactor > Extract > Extract Interface...
Keep in mind that the Extract Interface... option is not even in the menu if the class is static. The same goes for the class members if they do not appear in the menu where you select what goes in the interface.
I completely forgot that you cannot have a static class with an interface or extends at all for that matter.
-
2
Extract an interface refactoring
Place your cursor in the class name.
Press Ctrl+R, then Ctrl+I.
https://learn.microsoft.com/en-us/visualstudio/ide/reference/extract-interface?view=vs-2019
I had the same problem with Visual Studio Community 2019 and I fixed it by disabling Resharper.
For some users the menu on right click on the class seems be deleted and now you can access only by right clicking
on the class
that you want to create the interface and than click on Quick actions and refactoring
.