命名空间和基类无法识别-为什么?

问题描述 投票:0回答:1

所以我正在做某人给我的项目。

在项目中,有一个主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等的可访问性,对吧?

vb.net intellisense .net-assembly
1个回答
0
投票

我将此作为答案,因为它解决了我的问题。但是,我不知道是什么原因造成的,也不知道以“适当”方式实际解决问题的确切步骤。

我做了以下事情:

我将文件MyClassDerivedFromDevice.vb重命名为MyClassDerivedFromDevice_Old.vb,创建了一个名为MyClassDerivedFromDevice.vb的新类,并在添加了命名空间并确保Intellisense并确保一切正常之后,我只是从MyClassDerivedFromDevice_Old.vb复制了代码(在该行之后Namespace DevicesEnd NamespaceMyClassDerivedFromDevice.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(现在应该可以使用)。

© www.soinside.com 2019 - 2024. All rights reserved.