Is there a way in Visual Studio to right click an interface and 'Generate Class from Interface' so I end up with an empty class with all the properties and methods which the interface requires?
Kind of like Extract Interface, but backwards.
Is there a way in Visual Studio to right click an interface and 'Generate Class from Interface' so I end up with an empty class with all the properties and methods which the interface requires?
Kind of like Extract Interface, but backwards.
To specifically address this question, yes, there is. Caveat, I'm using C#, working with the Visual Studio 2013 Ultimate Edition.
Create an empty class, like "Class1":
class Class1
{
}
Then append an interface name, such as IObjectBase (which I'll continue to use for the remainder of this post), by using the ":", as in the following example:
class Class1:IObjectBase
When you do, there will be a short, thick, white underline, under the first letter of your interface name "I". Mouse-over it. There are a number of options which may appear. You're looking for a small icon which looks like a page with a dog-eared, top-right corner as you hover over the small, thick white line, with the tooltip of "Options to implement interface". Click on the drop-down arrow to its right.
You'll be presented with two menu item options: "Implement interface 'IObjectBase'" and "Explicitly implement interface 'IObjectBase'". From there the choice is yours.
If you're looking for guidance regarding the two options, I'd suggest reading the following articles, I think each covers the topic well, yet from different viewpoints:
Regards,
HALAR