如何在 Visual Studio 中为基础 Class 的方法自动创建一个空的覆盖方法?

How to Automatically Create an Empty Overriding Method for a Base Class's Method, in Visual Studio?

假设我创建了一个 class 继承自某些基础 class
(例如,假设我正在创建继承 class Controlclass AdvancedProgressBar
现在我想继承 一些 Control 方法。

如何在基class(Control)中专门选择一个方法,然后告诉Visual Studio为其创建一个空的覆盖方法?

使用 google 搜索时,我找到了这个提示:

In the ClassView window, expand the base class under your derived class.
Then right-click the desired method, and select Add.

我转到 Class 查看 window,找到我的 class (AdvancedProgressBar),展开 "Base Types" 子树,单击 Control,
然后找到一些方法,例如 OnGotFocus,
但现在当我右击 OnGotFocus 时,没有 "Add" MenuItem..

也许它在 VS2008 中不可用?
(如果确实不是,也许还有另一种方法,在 Visual Studio 2008 年?)

当您继承class 时,您将被迫继承所有publicprotected 方法和成员。如果您正在谈论哪些可以 override,Visual Studio 将在您键入 override 后通过智能感知告诉您。它看起来像这样:

protected override void inherited() => base.inherited();

当然,您可以省略对 base.inherited() 的调用,使其成为一个空的覆盖方法。

您不能在 VS2008 中从 Class 视图 window 执行此操作。但是,还有另一种方法。对于虚方法,当 编写实现子 class 的代码,只需键入 override,然后按 space。智能感知将 向您展示可用方法的列表。只需 select 您想要的那个,就会生成一个框架实现。 在抽象方法的情况下,单击您继承自的行上的父 class,将出现一个智能标记。 通过单击它或按 Ctrl+ 调用智能标记菜单。你会得到一个生成骨架的选项 抽象方法的实现。

如果您对这些 built-in 生产力助推器不满意,您将不得不寻找一些 VS 扩展。一个优秀的 Resharper

能让你做到这一点的扩展是 Resharper

https://www.jetbrains.com/resharper/

但它不是免费的,因此您必须决定它是否值得。