vb.net - 名称空间和基类无法识别 - 为什么?
问题描述
所以我正在做一个别人给我的项目。
在项目中,有一个 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或其他东西的可访问性产生影响,对吧?
解决方案
我写这个作为答案,因为它解决了我的问题。但是,我不知道它有什么原因,也不知道以“正确”方式实际解决问题的确切步骤。
我所做的是以下内容:
我将文件重命名MyClassDerivedFromDevice.vb
为MyClassDerivedFromDevice_Old.vb
,创建了一个名为MyClassDerivedFromDevice.vb
and 的新类,在添加命名空间并确保 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
推荐阅读
- javascript - 如何在我的 React JS 应用程序中显示常规 javascript?
- sql-server - SSIS 包在切换到不保存敏感文件后不起作用
- scala - 如何使用 sbt-native-packager 在 Docker 中使二进制文件可执行?
- apache - 来自 mod_rewrite 的 RewriteRule 仅可用作添加 http://%{HTTP_HOST} 的重定向,但没有它根本无法工作
- symfony - Symfony 4+ 表单验证在控制器操作中完成?
- reactjs - CORS 仅在 Firefox 和 Safari 上阻止内容且仅 onClick()
- react-native - 是否可以从 createStackNavigator 导航到 createDrawerNavigator?
- c# - 正确处理来自 C#/Java 应用程序的 OCSP 请求(+ BouncyCastle)
- html - 加载文本后,无法让 div 扩展到另一个 div 的高度
- vhdl - 错误:# ** 致命:(vsim-3807)端口“XOUT”的组件和实体之间的类型不匹配。尝试运行模拟时