首页 > 解决方案 > 名称空间和基类无法识别 - 为什么?

问题描述

所以我正在做一个别人给我的项目。

在项目中,有一个 main Namespace,我们称之为“ Program”。在该名称空间中有几个不同的类。

现在我必须从 Namespace 中的一个类派生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

这有效:

已经存在的ClassDerivedFromDevice.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.netintellisense.net-assembly

解决方案


我写这个作为答案,因为它解决了我的问题。但是,我不知道它有什么原因,也不知道以“正确”方式实际解决问题的确切步骤。

我所做的是以下内容:

我将文件重命名MyClassDerivedFromDevice.vbMyClassDerivedFromDevice_Old.vb,创建了一个名为MyClassDerivedFromDevice.vband 的新类,在添加命名空间并确保 Intellisense 和一切正常之后,我只是将代码从(MyClassDerivedFromDevice_Old.vb在排队Namespace Devices到.End NamespaceMyClassDerivedFromDevice.vb

这解决了问题。


简洁版本:

1)重命名NotWorkingClass.vbNotWorkingClass_Old.vb

2)添加新类名称NotWorkingClass.vb

3) 将命名空间添加到NotWorkingClass.vb.

4) 检查是否一切正常(Intellisense 等)并被 Visual Studio 识别。

5) 将所有代码复制到从到Namespace X到之前的所有代码(现在应该可以工作了)。End NamespaceNotWorkingClass_Old.vbNotWorkingClass.vb


推荐阅读