Visual Studio Tips - How to Refactor interface from a class

When you are developing a new functionality, you are not sure how the interface for your services will look like. It is good to have the interface defined first but it is not always the case. Like most of developers, you then end up creating a class and putting some meat in it. At some point you have defined all the methods that need to be exposed. So now you want to create an interface. I am not going to discuss here why I need an interface and things like that. Thats topic for another day.

Here is where Visual Studio 2010 will help you in automatically create an interface from your class.

  • Right click on class in editor window. It will bring up context menu as shown below.

  • Click on Refactor menu item and it will bring up next context menu as shown below.

  • Click on Extract Interface option and it will bring up dialog box as shown below.

  • Now you can configure name of interface, file name, methods and properties to include in the interface. Once you have made selection, click OK and you will have a new interface file in your project and your project will be modified to implement the interface that you just created.

Search

Social

Weather

-0.1 °C / 31.8 °F

weather conditions Clouds

Monthly Posts

Blog Tags