Override Members Using Class Designer

How do I do that?

Whether you program in C# or VB, you’ll notice that when you type “overrides” or “Overrides” in code editor, you get an intellisense list of members that you can override. This feature has also been exposed in Class Designer: In the right-click context menu of a Class shape, you can find “Override Members …” option under “Intellisense” sub-menu.

By invoking the command, you will get the following pop-up window:

Obviously, only those members that can be overridden are listed in the dialog. And I’d like to point out two major advantages of this UI over the flat intellisense list you get from code editor:

1. The tree view gives you a hierarchical view of where each member is defined. This is especially useful if there’s more than one level of inheritance, as shown in the following picture. This helps to determine whether you want to override a base implementation or not, without overriding an already-overridden one by mistake.

2. You can override multiple members at once. Imagine what you’ll do in code editor for your WinForm control:

As a side note, you may have noticed that the signature syntax is language-specific, just as everywhere else in ClassDesigner.

What members are listed in the dialog?

The list of members in the Override Members dialog is dynamically calculated, so it accurately reflects the state of your program when you invoke it. It only shows those parent members that are valid to be overridden, which means the following possibilities:

- The member is defined as “abstract”/“MustOveride” or “new abstract”/“Shadows MustOverride”. (Note that abstract members are also automatically implemented in derived class when you drag-drop the inheritance line; and can be implemented through Intellisense->Implement Abstract Class menu item)

- The member is defined as “virtual”/“Overridable” or “new virtual”/“Shadows Overridable”.

- The member is defined as “override”/“Overrides”.

- The member is NOT defined as “override sealed”/“Overrides NotOverridable”

- The member is NOT defined as “static”/“Shared”

- The member is NOT already overridden.

Note: Unfortunately, we can’t override C# indexer (“this”) in this release, so it will not show up in the Override Members dialog.

What about J#?

There is no “override” keyword in J#, any instance member not defined as “final” can be overridden by derived class, so what can you do when you want a list of members that you can override? You can use Class Designer! The Override Members feature is also supported for J# in ClassDesigner with the exact look and feel as the other two languages. In J#, “final” keyword will be the only case to stop an instance member from being considered as overridable.

Undo/redo?
Sure. Just like any other operations you can perform in ClassDesigner, the Override Members operation supports undo/redo as well. There will a single undo/redo action for Override Members, whether you override one member or multiple members at the same time.

Thanks,

Frank Fan

Visual Studio Class Designer Team