Code Generation for Overrides in Visual Basic .Net 2005

VBTeam

 

by Mike Carter

Some subtle changes were made in Visual Basic .Net 2005 to make code generation of overidden methods a little easier.  In Visual Basic .Net 2003 and earlier, you used the code dropdowns as in Figure 1 below.

Figure 1

When overriding a Sub, a declaration stub similar to the following was generated in the editor.

Public Overrides Sub MyOverridableSub()

End Sub

In Visual Basic .Net 2005, you never have to leave the code editor.

Figure 2

You can generate a method stub for your overridable methods by just entering “overrides ” on a new line in the editor, as in Figure 2. An Intellisense window is displayed with a list of all overridable members in entire iheritance hierarchy for the inherited class.  In this case, BaseClass which inherites from System.Object.  Therefore, overridable members from BaseClass and System.Object are displayed.  When you select a method,  a declaration stub is generated with a call to the base method similar to the following.

Public Overrides Sub MyOverridableSub()

MyBase.MyOverridableSub()End Sub

This is just one subtle way in Visual Basic .Net 2005 in which we are trying to make your development experience a little easier.

0 comments

Leave a comment

Feedback usabilla icon