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.
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.
Not really sure if this feature was already there or got implemented afterwards, but I found this:
First, extract the interface as usual

Then you get to do this on your methods:

Note that it doesn't add necessary usings but uses namespaces instead. You can do the clean up as you like.
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