简体   繁体   English

命名空间/类限定符

[英]Namespace / Class Qualifier

I have a solution with several projects. 我有几个项目的解决方案。 One of them is Contexts (where the default namespace is XYZ), and another is BackOffice (where the default namespace is XYZ.BackOffice). 其中一个是上下文(默认名称空间为XYZ),而另一个为BackOffice(默认名称空间为XYZ.BackOffice)。 BackOffice has a reference to Contexts. BackOffice引用了上下文。

I created a new class (Foo) in Contexts and I specified that Foo's namespace is XYZ. 我在上下文中创建了一个新类(Foo),并指定Foo的命名空间为XYZ。 I then wrote some code in BackOffice that used Foo. 然后,我在BackOffice中使用Foo编写了一些代码。 I DID NOT QUALIFY Foo when I used it, nor did I add a using directive, and the build failed, as I expected. 当我使用Foo时,我没有使Foo合格,也没有添加using指令,并且构建失败,正如我期望的那样。 I then changed all Foo to XYZ.Foo and did another build. 然后,我将所有Foo都更改为XYZ.Foo并进行了另一个构建。 This time it was successful. 这次成功了。 I then removed the XYZ's that I had just added, and the build is STILL successful. 然后,我删除了刚刚添加的XYZ,并且构建仍然成功。

How is it now "remembering" the namespace? 现在如何“记住”名称空间? I did a clean and rebuild; 我进行了一次清洁和重建; no change. 没变。 I dropped Foo from Contexts and re-add it; 我从上下文中删除了Foo并重新添加了它; VS2008's automatic error checking showed the errors I expected, but then the next build was still successful. VS2008的自动错误检查显示了我所期望的错误,但是随后的构建仍然成功。

This only bothers me because I fear that, although I get a successful build, when my teammates check out my code, they may not. 这只会让我感到困扰,因为我担心尽管构建成功,但是当我的队友签出我的代码时,他们可能不会这样做。

You must have a namespace qualifier somewhere. 您必须在某处具有名称空间限定符。 It may have a using somewhere that didn't get removed. 它的使用可能没有被删除。 Close your project and reopen. 关闭您的项目,然后重新打开。 Sometimes there is a cached version of VS projects that probably is not getting updated in your case. 有时,您的案例中可能没有更新VS项目的缓存版本。 Not sure what else to look for. 不知道还要寻找什么。

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

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