简体   繁体   English

同一类的两个名称空间

[英]Two namespaces of the same class

we are changing the name of our product, so i also want to rename the namespaces of our framework-classes. 我们正在更改产品的名称,因此我也想重命名我们的框架类的名称空间。 But now i have the problem, that i don't know in which programms and scripts our namespaces are used. 但是现在我有了问题,我不知道我们的命名空间在哪些程序和脚本中使用。 Is there a way in c#, to locate the same class in two different namespaces? 在c#中,有没有一种方法可以在两个不同的名称空间中找到相同的类?

I know the solution, that i could inherited from my classes in the new namespace, but this is a very bad solution i think. 我知道可以从新命名空间中的类继承的解决方案,但是我认为这是一个非常糟糕的解决方案。 So I have no idea how to solve this problem, because simply renaming all namespaces doesn't help and will cause a lot trouble. 因此,我不知道如何解决此问题,因为仅重命名所有名称空间无济于事,并且会造成很多麻烦。

Thank you! 谢谢!

If external scripts are referencing your assembly using the old namespace names then those names will have to remain in your assembly in you wish to continue to use those scripts. 如果外部脚本使用旧的名称空间名称引用程序集,则这些名称将必须保留在您的程序集中,以便您继续使用这些脚本。 If you also want to create new namespace names to reflect the new name of your product, those names will also need to be hardcoded into your assembly. 如果您还想创建新的名称空间名称以反映产品的新名称,那么这些名称也需要硬编码到程序集中。 This will inevitably lead to problems! 不可避免地会导致问题!

I would recommend one of the following: 我建议以下之一:

  1. Leave the namespace names as they are. 保留名称空间名称不变。
  2. Rename the namespaces in full and update the Python scripts at the same time. 重命名名称空间,并同时更新Python脚本。

I would definitely not recommend the faux 'inheritance' method, or any other solution which results in duplication within the assembly. 我绝对不建议您使用伪造的“继承”方法或任何其他导致程序集重复的解决方案。

You could search the whole project / solution of course, but that seems sort of messy and time-consuming too, if you've got more than a trivial project. 当然,您可以搜索整个项目/解决方案,但是如果您不只是一个琐碎的项目,那似乎也很麻烦且耗时。

Are you using Resharper? 您在使用Resharper吗? For this type of task, you definitely should be. 对于此类任务,您绝对应该如此。 If so, there is a chance this could at least help you on your way: 如果是这样,那么这至少有可能帮助您:

  • Rename the folders your source files are in in the Visual Studio Solution Explorer (this should in theory be easier than looking at each source file one by one, right?). 重命名源文件在Visual Studio解决方案资源管理器中的文件夹(从理论上讲,这应该比逐个查看每个源文件更容易,对吗?)。
  • Now open one source file that you know will have the wrong namespace due to a renamed folder. 现在,打开一个您知道由于重命名文件夹而导致名称空间错误的源文件。 It should appear with a blue squiggly line, as in the picture below. 如下图所示,它应显示为一条弯曲的蓝色线条。
  • Use the Resharper tip (pyramid to the left, or Alt + Enter ) to open the context meny thingy also shown below. 使用Resharper提示(左侧的金字塔,或Alt + Enter )打开上下文菜单,也如下所示。
  • Select Find all issues of this type in scope , and select Solution as your scope. 选择“在范围中查找所有此类问题” ,然后选择“ 解决方案”作为您的范围。 That might at least help you get an overview of which classes you need to change the namespaces for, and go through them and change them systematically. 这至少可以帮助您大致了解哪些类需要更改其名称空间,并遍历它们并系统地对其进行更改。

在此处输入图片说明

As for your scripts, I would guess that you best bet is to do a plain text search for the old namespaces - possibly a search and replace . 至于您的脚本,我想您最好的选择是对旧名称空间进行纯文本搜索-可能是搜索和替换 Perhaps you can include your scripts in a VS solution, and use the built in search there to scan and fix them. 也许您可以将脚本包括在VS解决方案中,然后使用那里的内置搜索来扫描和修复它们。 That might at least ease the pain a little.. 那至少可以减轻一点痛苦。

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

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