Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you auto-implement an interface in C#?

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.

like image 285
RLH Avatar asked Jul 24 '13 20:07

RLH


2 Answers

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.

like image 74
Cam Bruce Avatar answered Sep 19 '22 11:09

Cam Bruce


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

like image 36
Curtis Rutland Avatar answered Sep 19 '22 11:09

Curtis Rutland