共用方式為


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

  • Anonymous
    March 10, 2004
    You can always right click on the interface in the class browser and click Add | Implement interface.

    ie:

    ClassName
    -- Bases and Interfaces
    - IInterfaceName (Right click on this one and select Add | Implement Interface
  • Anonymous
    March 11, 2004
    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... :/
  • Anonymous
    March 11, 2004
    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.
  • Anonymous
    March 12, 2004
    The comment has been removed
  • Anonymous
    March 17, 2004
    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.

    Omer
  • Anonymous
    March 18, 2004
    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.
  • Anonymous
    March 21, 2004
    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

    Oskar
  • Anonymous
    March 30, 2004
    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.
  • Anonymous
    June 14, 2004
    The comment has been removed