简体   繁体   English

命名空间阴影类名称

[英]Namespace Shadowing Class Name

I have the following situation: 我有以下情况:

A compiled library with the namespace Library which contains class Feauture . 具有名称空间Library已编译库,其中包含Feauture类。

Now there is another library in development, one which intends to utilize the feature, and that has been dubbed Library.Feature . 现在有另一个正在开发中的库,打算利用该功能,并且被称为Library.Feature Finally there is a third library: Library.Feature.UI . 最后,还有第三个库: Library.Feature.UI

When working in the Library.Feature.UI project, which has both other libraries referenced, VS is yelling a lot about trying to using the Feature class, because it is seeing it primarily as a namespace. 在同时引用了两个其他库的Library.Feature.UI项目中工作时,VS大喊大叫尝试使用Feature类,因为它主要将其视为命名空间。

I've tried a few different using directives to get around this, as well as trying to qualify the class name, but nothing is working. 我尝试了几种不同的using指令来解决此问题,并尝试限定类名,但是没有任何效果。

Assuming I don't have the ability to change any of the namespaces or existing class names, is there a way to circumvent this issue? 假设我没有能力更改任何名称空间或现有的类名,是否有办法避免此问题?

您可以在指定名称空间的同时使用全限定名和类型名,也可以使用using指令创建别名:

using MyFeature = Library.Feature;

这应该可以解决问题(参考)

using FeatureClass = Library.Feature;

You can use alias directives to give a different name to any namespace, and then use that alias to reference that namespace. 您可以使用别名指令为任何名称空间赋予不同的名称,然后使用该别名来引用该名称空间。

By doing this you can differentiate between the class and the namespace. 通过这样做,您可以区分类和名称空间。

write the following on top while using namespaces. 使用名称空间时,请在顶部写以下内容。

using FeatureClass = Library.Feature;

For more knowledge on this, you can refer: https://msdn.microsoft.com/en-us/library/aa664765%28v=vs.71%29.aspx 有关此的更多知识,请参阅: https : //msdn.microsoft.com/zh-cn/library/aa664765%28v=vs.71%29.aspx

Let me know if you have any further issue... 让我知道您是否还有其他问题...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM