Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VS Code: Extract interface in C#

I'm using VS Code and I can't figure out if it's possible to take a class and extract an interface from it. When I google how to do this, I only find extensions for TypeScript, but I want to do this in C#.

Can VS Code extract interfaces? Knowing the shortcut would be nice for others, but I'm using a different keymap, so I'd like to know how to do this from the menu.

like image 588
Daniel Kaplan Avatar asked Dec 22 '18 21:12

Daniel Kaplan


2 Answers

You may try this,

Move your cursor on the class_name that you want to extract interface. Then Ctrl + . (period) Then choose "Extract Interface" this will generate a code above the class that you want to be extracted. Then move your cursor the interface class_name Ctrl + . (period) again, then choose "Move type to the" auto-generated class name then that's it.

Hope this will help you guys and for future reference.

like image 104
OnceACurious Avatar answered Sep 22 '22 02:09

OnceACurious


Not really sure if this feature was already there or got implemented afterwards, but I found this:

First, extract the interface as usual

Extract interface

Then you get to do this on your methods:

Extract signature

Note that it doesn't add necessary usings but uses namespaces instead. You can do the clean up as you like.

like image 39
uTeisT Avatar answered Sep 19 '22 02:09

uTeisT