所以我正在做某人给我的项目。
在项目中,有一个主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
我缺少什么吗?好像有一个我必须激活的隐藏设置吗?
编辑:声明看起来像这样(但是在不同的文件中):
Device.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等的可访问性,对吧?
我将此作为答案,因为它解决了我的问题。但是,我不知道是什么原因造成的,也不知道以“适当”方式实际解决问题的确切步骤。
我做了以下事情:
我将文件MyClassDerivedFromDevice.vb
重命名为MyClassDerivedFromDevice_Old.vb
,创建了一个名为MyClassDerivedFromDevice.vb
的新类,并在添加了命名空间并确保Intellisense并确保一切正常之后,我只是从MyClassDerivedFromDevice_Old.vb
复制了代码(在该行之后Namespace Devices
至End Namespace
至MyClassDerivedFromDevice.vb
。
解决了问题。
简短版:
1)将NotWorkingClass.vb
重命名为NotWorkingClass_Old.vb
2)添加名称为NotWorkingClass.vb
的新类。
3)将命名空间添加到NotWorkingClass.vb
。
4)检查是否一切均正常工作(Intellisense等),并且Visual Studio可以识别。
5)将Namespace X
之后的所有代码从End Namespace
复制到NotWorkingClass_Old.vb
之前的位置NotWorkingClass.vb
(现在应该可以使用)。