VS 2003 Tip #7: Implementing interface stubs automatically

In Everett, we added a feature to add interface stubs to your code automatically, when you wanted to derive from an interface. To do this simply type out “:” after your class name, type your interface to derive from and you should see a little tooltip pop up that says “Press TAB to implement stubs for interface Ifoo”. Hit Tab and enjoy VS putting in the stubs for you. If you happen to delete the interface and retype a newer one, you might not see the tooltip again. To get it, erase all the way to the “:”. Enjoy...

Comments (16)

  1. Matt Berther says:

    You can always right click on the interface in the class browser and click Add | Implement interface.



    — Bases and Interfaces

    – IInterfaceName (Right click on this one and select Add | Implement Interface

  2. Please, oh please(!), stop placing the implementation stubs in a region… Or at least give me an option to disable it… It’s pretty annoying… :/

  3. Shaykat says:

    Hi Omar – you can disable the region getting collapsed (I think thats what you want) by turning the option off in Tools.Options.Text Editor.C#.Formatting.Outlining.Collapse # region blocks when files open.

  4. JuanC says:

    It would be nice if whibey could support "shift-tab" to force an "explicit" interface implementation.


    void ITest.Foo1()



    void ITest.Foo2()



  5. Hey Shaykat,

    I was referring to not placing a region at all on the section.

    And anyway, the "Tools.Options.Text Editor.C#.Formatting.Outlining.Collapse # region blocks when files open" option is too generic. I want it turned on, but I just want the #region pp-directive not written for interface implementations.


  6. Blake Ryan says:

    I’ve noticed that an easier way to get the completion tooltip again is to type a comma after then interface name and then backspace it away. The implement interface tooltip will appear.

  7. Oskar Austegard says:

    Have a look at what the JetBrains folks are planning for ReSharper regarding this: http://www.intellij.net/forums/thread.jsp?forum=37&thread=78680&tstart=0&trange=15#852024


  8. Brian Morearty says:

    My 2 cents: I love that it creates a #region around the methods.

    I agree with the suggestion to provide a way to put the interface name on the methods. E.g., IDisposable.Dispose instead of just Dispose.

    Awesome feature, by the way. Easy, useful, and discoverable.

  9. Kiwidude says:

    A nice feature in theory, apart from one hugely awful bug. If your interface defines two methods with the same name overloaded, the "stubs" are only correct for one of the overloads. You end up with a mess of uncompilable code, which you have to manually edit by adding back in the ‘public’ modifier and removing the fully qualified namespace that it puts on the method name… a pretty crappy effort imho. Does anyone have a justification for why it does this or how on earth it got through "quality control"???

Skip to main content