如何使含有'系统'在.NET中没有它矛盾的命名空间?矛盾、系统、空间、NET

由网友(生人勿扰)分享简介:有时候,我做了在C#中的命名空间(我不知道问题出在VB.NET一样的)含有'系统',当我从不同的DLL包括它它都疯了,用含一切冲突'系统'。这导致了疯狂的错误,如以下内容:Sometimes I've made a namespace in C# (I don't know if the problem is the...

有时候,我做了在C#中的命名空间(我不知道问题出在VB.NET一样的)含有'系统',当我从不同的DLL包括它它都疯了,用含一切冲突'系统'。这导致了疯狂的错误,如以下内容:

Sometimes I've made a namespace in C# (I don't know if the problem is the same in VB.NET) containing 'System' and when I include it from a different DLL it goes crazy and conflicts with everything containing 'System'. This leads to crazy errors such as the following :

类型或命名空间名称   'ServiceModel'中不存在   命名空间RR.System

The type or namespace name 'ServiceModel' does not exist in the namespace 'RR.System'

类型或命名空间名称'运行'   在命名空间中不存在   RR.System

The type or namespace name 'Runtime' does not exist in the namespace 'RR.System'

类型或命名空间名称   'SerializableAttribute'不存在   在命名空间RR.System

The type or namespace name 'SerializableAttribute' does not exist in the namespace 'RR.System'

如果你不知道我说的那么好,你:)我敢肯定,许多人都看到了这个问题。

If you don't know what I'm talking about then good for you :) I'm sure many have seen this issue.

我不完全知道为什么它这样做。它会发生,即使在文件中,如产生code为不包含任何引用 RR.System Web服务。

I'm not completely sure why it does this. It will occur even in files, such as generated code for web services that doesn't contain any reference to RR.System.

这一切都发生只是因为我包括 RR.System 的DLL在不同的项目中。

This all occurs just because I'm including RR.System the DLL in a different project.

如何才能避免这种情况的发生?或者修复它?

How can I avoid this happening? Or fix it?

推荐答案

我还是不明白为什么一个的孩子的命名空间用的根的命名空间的冲突?所有类型下一个命名空间可以完全胜任,和完全合格的名称指的是不同类型的。例如,

I still don't see why a child namespace conflicts with a root namespace? All types under a namespace can be fully qualified, and the fully qualified names refer to different types. e.g.

System.Abc.Xyz.Type

没有任何关于

has nothing in relation to

Abc.Xyz.System.Type

系统在第一种情况指的是完全不同的概念(在本准则的公司名称),而系统在第二种情况可能是指产品或子系统的名字。

The System in the first case refers to a completely different concept (The Company name under the guidelines), whereas the System in the second case could refer to the product or subsystem name.

如果根命名空间可能会导致这种干扰​​的话,想必这是一个大问题,因为我可能会选择打电话给我新的热带雨林监控产品亚马逊键,把我所有的类型在 MyCompany.Amazon 。再后来我可能会选择使用存储在S3存储和突然的命名空间亚马逊会导致冲突我的数据。

If root namespaces can cause this kind of interference then surely that's a big problem because I may choose to call my new rainforest monitoring product Amazon and put all my types under MyCompany.Amazon. Then later on I may choose to store my data using the S3 storage and suddenly the namespace Amazon causes a conflict.

我们刚刚遇到同样的问题,因为我们的项目分为3个主要的子系统 - 数据库,用户和系统。这似乎是在我们的MyCompany的根命名空间显而易见的孩子命名空间。

We've just run into the same issue as our project is split into 3 major sub-systems - Database, User and System. These seem like obvious child namespaces under our MyCompany root namespace.

记住,这有没有关系using语句西蒙说:这会发生,即使在文件中,如产生code为不包含任何引用RR.System Web服务

Remember, this has nothing to do with Using statements as Simon said "It will occur even in files, such as generated code for web services that doesn't contain any reference to RR.System"

更新:下面的堆栈溢出的问题是沿着相同的路线。但是MSDN文章它指向讨论所谓的系统隐藏着一个命名空间(够公平),并且还使用系统作为顶级命名空间(足够公平)一类的名称。然而,它没有讨论为​​什么一个根一个孩子名字空间的冲突。

UPDATE: The following Stack Overflow question is along the same lines. However the MSDN article it points to discusses a class name called System hiding a namespace (fair enough) and also using System as a top-level namespace (fair enough). However it does not discuss why a child namespace conflicts with a root one.

堆栈溢出问:是全球::不好在C#code味道? MSDN文章:如何:使用命名空间别名限定符

Stack Overflow Q: Is global:: a bad code smell in C#? MSDN Article: How to: Use the Namespace Alias Qualifier

阅读全文

相关推荐

最新文章