Visual Studio tip: easily create an interface from a C# class with the Extract Interface refactoring

Posted: (EET/GMT+2)

 

Today's blog post is a quick Visual Studio tip that allows you to easily create an interface from an C# class. This allows easier unit testing, for example.

To create an interface automatically, do the following. First, position your caret (the blinking one) in the Code Editor to a name of a class. Then, select to the menu command "Edit/Refactor/Extract Interface". A new dialog box opens on the screen. You can also press the shortcut key Ctrl+R, I.

In the dialog box, select the methods you want to declare in the interface. By default, all methods are selected. Next, simply click OK, and your interface is generated.

Happy hacking!