New For VS2005 - Abstract Stub Generation
Visual Studio 2005 includes a new feature to generate stubs for methods in an abstract base class. Here's an example of how it works.
Suppose you want to create a class called MyDerivedClass that inherits from an abstract class called MyAbstractClass:
Before Visual Studio 2005, you would have had to look up and then type in the function prototypes for each of the abstract methods in the inheritance chain for MyDerivedClass. Just finding these methods to implement can be hard because the inheritance chain may include multiple abstract classes and any ancestor class can implement any abstract method. If you had the source code to all of the classes in the inheritance chain you could figure out which methods were still abstract for your class and then go to their definitions and copy-paste the function prototypes, replacing the abstract keyword with override. If you didn't have the source code for the entire inheritance chain, you might end up using the Object viewer to identify and copy the function definitions. Either way, you would be in for a bit of work.
In Visual Studio 2005, a small blue rectangle called a smart tag appears whenever you start to declare a class that derives from an abstract type:
Hovering over the tag or pressing Shift+Alt+F10 will produce a menu of alternatives for implementing the abstract methods:
Clicking on the down arrow opens the menu, which in this example shows a single option:
Invoking this option implements stubs for the overrides of the abstract methods as follows:
It’s that easy. Now all you need to do is fill in the implementation for each method and you are up and running.
Hope this helps.
Mike
Comments
Anonymous
December 05, 2006
You've been kicked (a good thing) - Trackback from DotNetKicks.comAnonymous
December 07, 2006
Or you can just press <TAB> and you will get the same results (no need to get hold of that dirty mouse!)Anonymous
December 07, 2006
Anastasiosyal: Thanks for your comment. I am also a fan of keyboard access, but don't know how to use <TAB> in this scenario. The <TAB> key works when using Intellisense to match and then complete an identifier that has been partially entered. In the case of stub generation you can open the smart tag menu with <CTRL>-. (Karen Liu tells me this is the preferred key binding for the C# profile) or <SHIFT>-<ALT>-<F10> as mentioned above. Once the menu is open you can use the arrow keys or <TAB> or <SHIFT>-<TAB> to move through the menu items, but you need to hit <ENTER> to select an item or <ESC> to cancel the menu. In any event - you don't need to use the mouse. Hope this helps. -MikeAnonymous
December 07, 2006
It's very nice and informative one.Anonymous
December 08, 2006
This is a great feature, I use it daily.Anonymous
July 22, 2008
Ultracet. Is ultracet a narcotic.Anonymous
July 29, 2008
The comment has been removed