How to easily create an interface from a class?

I have a class that has 10 methods. I want to create an interface of this class, i.e. The interface will contain only the signature of these 10 methods.

Is it easy to do this in .NET with Visual Studio?

I ask this question because I am changing the architecture of my project and for every class present in my project I need an interface.

+4
source share
5 answers

Of course it can. You can use the Extract refactoring interface to do this for you.

0
source

If you are using VS 2010, you can do this simply by going to the Refractor menu and pressing Extract Interface, you can also use a short keyboard shortcut Ctrl + R , I

+6
source

Ctrl + C , Ctrl + V. Pretty easy. Think about it!

seriously, Ctrl + R , Ctrl + I - will extract the class interface.

+2
source

Sounds like work for the ReSharper refactoring function Extract Interface .

0
source

There are several ways:

  • Method 1: Using Visual Studio: right-click on your class and select Refactor>Extract Interface , then select Members and specify an Interface name or keep the default name if you want the leading I in the name of your class.
  • Method 2: after opening the class press Ctrl + R , I (case insensitive), and then complete the rest task in accordance with Way 1
0
source

Source: https://habr.com/ru/post/1385282/


All Articles