Deviprasad Das
Deviprasad Das

Reputation: 4363

How to create an interface out of a class easily?

I have a class which has 10 methods. What i want is to create an interface of that class, i.e the interface will contain only the signature of those 10 methods.

Can it be done easily in .NET using Visual studio?

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

Upvotes: 4

Views: 300

Answers (5)

Elias Hossain
Elias Hossain

Reputation: 4469

There are several way to go:

  • Way 1: Using Visual Studio: Right Click on your Class body and the choose Refactor>Extract Interface, then choose Members and provide Interface name or keep default name if you want leading I in your class name.
  • Way 2: After opening your class, press Ctrl+R,I(case insensitive) and then do rest job according to Way 1

Upvotes: 0

stukselbax
stukselbax

Reputation: 5935

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

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

Upvotes: 2

Vamsi
Vamsi

Reputation: 4253

If you are using VS 2010 you can do this by just going to the Refractor Menu and click Extract Interface, you can also use the key board short cut Ctrl+R, I

Upvotes: 6

Marty
Marty

Reputation: 7522

It certainly can. You can use the Extract Interface refactoring to do it for you.

Upvotes: 0

Chris Fulstow
Chris Fulstow

Reputation: 41872

Sounds like a job for ReSharper's Extract Interface refactoring feature.

Upvotes: 0

Related Questions