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 

 

kick it on DotNetKicks.com