简体   繁体   中英

Namespace Shadowing Class Name

I have the following situation:

A compiled library with the namespace Library which contains class Feauture .

Now there is another library in development, one which intends to utilize the feature, and that has been dubbed Library.Feature . Finally there is a third library: 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.

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.

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

Let me know if you have any further issue...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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