c# - 如何让 Visual Studio Intellisense 发现继承的子类?

标签 c# .net visual-studio visual-studio-2012 intellisense

我有一个场景,其中 Visual Studio (2012) Intellisense 无法识别在继承类中定义的子类。最好用一个简单的例子来证明它:

public class Shape {

    public class SubShape {
    }

}

public class Circle : Shape {
}

所以我有一个带有 SubShape 子类的 Shape 类,以及继承自 Shape 的 Circle。

如果我随后尝试使用 new Circle.SubShape() 实例化 SubShape 的实例,我在 new Circle. 之后无法从 Visual Studio 的 Intellisense 获得任何结果。一切都正确构建,没有语法错误。

如果我使用 new Shape.SubShape() 从基类引用该类,Intellisense 会起作用。如果我最初不使用 new 关键字,它也能正常工作——因此键入 Circle. 会向我显示 SubShape 作为一个选项。

我使用的是 Visual Studio 2012,版本 11.0.61030.00 Update 4

更新:我禁用了 ReSharper,但如果我打开它并选择使用 ReSharper 的 Intellisense 而不是 Visual Studio 的,一切都会按预期工作。

最佳答案

这可能是一个 Intellisense 错误(非常小),也发生在 VS2010 中。

奇怪的是,声明一个变量 do 具有 Intellisense,即两者兼而有之

Shape.SubShape s;
Circle.SubShape s;

键入时,将在点后列出子形状。

关于c# - 如何让 Visual Studio Intellisense 发现继承的子类?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22645214/

相关文章:

c# - 如何创建 'Private' ResourceDictionary?

c# - "Copy Local"和项目引用的最佳实践是什么?

c# - UWP 中 AppDomain.GetAssemblies() 的等价性?

c# - 如何在 C# 中创建嵌套(父子)JSON 响应?

c# - 为什么 C# 编译器区分这两种情况?

c# - WebApi 核心项目调试卡在 await client.GetAsync 上

c# - 检查 SqlDataReader 对象中的列名

c# - Label_ 标记在 Reflector 中来自哪里,如何破译它们?

asp.net - SendGrid 不从 Azure Windows 2012 VM 发送电子邮件

visual-studio - Visual Studio 将拖到工具箱上的代码块保存在哪里