我有一个场景,其中 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/