【发布时间】:2020-05-09 16:40:23
【问题描述】:
所以我正在做一个别人给我的项目。
在项目中,有一个主要的Namespace,我们称之为“Program”。
在该命名空间中有几个不同的类。
现在我必须从命名空间Devices 中的一个类派生。
已经有另一个类派生自对象Device。
所以我继续,创建了我的类,将它包含在 Devices 命名空间中,从 Device 派生它并完成了我的工作。
但不久之后,我无法使用任何基本变量、方法等。整个智能感知不适用于该课程。 更糟糕的是,它似乎没有包含在程序集中。
如何让 Intellisense、程序集等识别我的课程?我做了一个测试类,只是这样:
Namespace Devices
Class Testcle
' ... Nothing
End Class
End Namespace
而且效果很好。它被包含在程序集中,Intellisense 工作,等等。
文件夹结构有点像这样:
[Project]
↳ [-] Devices (Folder and Namespace)
[-] AlreadyExistingClassDerivedFromDevice (Folder)
↳ AlreadyExistingClassDerivedFromDevice.vb
[-] MyClassDerivedFromDevice (Folder)
↳ MyClassDerivedFromDevice.vb
↳ [+] Other (Folder)
↳ Testcle.vb
↳ Device.vb
我有什么遗漏吗?比如有没有我必须激活的隐藏设置?
编辑: 声明看起来有点像这样(但在不同的文件中):
设备.vb
Namespace Devices
Public MustInherit Class Device
' ...
End Class
End Namespace
这行得通:
AlreadyExistingClassDerivedFromDevice.vb
Namespace Devices
Public NotInheritable Class AlreadyExistingClassDerivedFromDevice
Inherits Device
' ...
End Class
End Namespace
这不起作用:
MyClassDerivedFromDevice.vb
Namespace Devices
Public NotInheritable Class MyClassDerivedFromDevice
Inherits Device
' ...
End Class
End Namespace
继承类实际上没有区别。只有内部运作。但是那些不应该对ctor或Intellisense或其他东西的可访问性产生影响,对吧?
【问题讨论】:
-
你有
Public Class Testcle还是只有Class Testcle? -
是
Public NotInheritable Class MyClassDerivedFromDevice Inherits Device -
那么,哪一个不工作?
MyClassDerivedFromDevice.vb还是Testcle.vb?你能发布他们的声明,包括额外的/嵌套的命名空间吗? -
MyClassDerivedFromDevice.vb不工作。是的,我会尽快将它们缩小到最低限度。不幸的是,我现在没有时间。 -
既然您提到了与命名空间有关的文件夹结构(“设备(文件夹和命名空间)”),我怀疑您已经习惯了在将类添加到文件夹; VB 不这样做。您必须使用 NameSpace 块显式包装类。您可以使用“类视图”(View Menu->Other Windows->Class View)来确定类在命名空间树中的位置。使用最小化的代码发布,很难推测问题出在哪里。
标签: vb.net intellisense .net-assembly