Extract and implement interfaces in Visual Studio using CodeRush

I recommend

A CodeRush feature that comes in very handy from time to time is the ability to easily extract and implement interfaces in Visual Studio.

This tip involves using the Refactor command included with CodeRush/Refactor Pro. The default shortcut key is Ctrl + ` .  Personally I prefer to map the Refactor command to Ctrl + R for a more convenient key stroke. I show how to do the mapping in the screen cast embedded later in this blog post.

Extract an interface from a class

You can easily extract interfaces from an existing class. With the cursor on a class, bring up the Refactor menu and select Extract Interface.

Visual Studio CodeRush Extract Interface

This will create an interface that contains the public properties and methods of the class. You can then move the interface to it’s own file by using the Refactor menu once again and select Move Type to File.

CodeRush Move Type To File Interface

Create an interface implementation

You can very quickly create and interface implementation. With the cursor on an interface, bring up the Refactor menu and select Create Implementer. You can choose to create an implicit or explicit implementation.

Visual Studio CodeRush Implement Interface

You can quickly move the implementation to a separate file the same way as shown above for extracting an interface.

I created a screen cast to show this in action:

CodeRush/Refactor Pro is a rock’in Visual Studio add-on from DevExpress.

I hope this helps!

Technical Visual Studio CodeRush August 2, 2010


Comments