11

Previously in Visual Studio, if you declared a class with an interface you could put your cursor on the interface, right-click it and select Implement Interface. (See here for a similar question for VS 2008.)

I've started working on a project that has defined numerous interfaces that will be used with SimpleInjector. Now, as I am beginning to write my service classes, I've noticed that the Implement Interface menu option is gone.

How can I implement all necessary method stubs like I could in VS 2008?

Sorry if this is a duplicate, however, I couldn't find this answer anywhere.


EDIT NOTES - Aug 17, 2018

This has been a hot question over the years. I've updated the title and tags for this so that it covers all pertinent versions of C# and Visual Studio.

This was ultimately a coder FAIL on my part. Much like classes, interfaces when generated by VS aren't defined as public. You will have to manually modify the interface declaration with the public accessor since VS doesn't automatically add it. It's easy to forget this step because you don't have to set member modifiers within the interface since, by definition, they will all be public.

4

3 回答 3

10

That hasn't changed. All you need to do is hover over the interface name in the class, and the blue underline bar should show up, giving you options to implement the interface. If the blue underline is not appearing, check to make sure the interface is accessible with what assemblies and namespaces you are referencing.

于 2013-07-24T20:26:38.653 回答
9

When you look at the interface name, you should see a little blue underline:

first image

If you hover over it, a drop down menu will appear, letting you implement the interface:

second image

于 2013-07-24T20:28:29.603 回答
7

Put your cursor somewhere in the interface text (the part after the colon) and hit Ctrl + .

于 2013-07-24T20:33:07.960 回答