C# 使用 ReSharper 更新命名空间的最快方法?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/791253/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-05 01:16:47  来源:igfitidea点击:

Fastest way to update namespaces with ReSharper?

c#resharper

提问by leora

I have been doing some refactoring and reorganization and I have moved a bunch of files around.

我一直在进行一些重构和重组,并且移动了一堆文件。

I want to update each file so it has the "correct" namespace according to its new location. With ReSharper, I can go into each file and it shows me that the namespaces is incorrect but that way I have to do it each file at a time.

我想更新每个文件,使其根据新位置具有“正确”的命名空间。使用 ReSharper,我可以进入每个文件,它告诉我命名空间不正确,但这样我必须一次对每个文件进行一次。

Is there anyway to update namespaces across every file in a folder or a project?

无论如何要更新文件夹或项目中每个文件的命名空间?

采纳答案by Iain Holder

UPDATE: Anyone reading this question with R#5.0 and above should note that this is now a feature:

更新:使用 R#5.0 及更高版本阅读此问题的任何人都应该注意,这现在是一个功能

ReSharper -> Refactor -> Adjust Namespaces...

ReSharper -> 重构 -> 调整命名空间...

回答by ema

I think that R# doesn't have this function. You can use CTRL-SHIFT-H to find&replace the string.

我认为R#没有这个功能。您可以使用 CTRL-SHIFT-H 来查找和替换字符串。

回答by Mark Worth

This isn't quite what you want to do ... but hopefully it's helpful.

这不是你想要做的......但希望它会有所帮助。

Go to the class view, and rename the namespace using Ctrl+R,R. It will update that namespace in all the files/folders that it's used in. As long as your namespaces are consistant, it should acheive the same result as changing all the namespaces in a folder.

转到类视图,并使用 Ctrl+R,R 重命名命名空间。它将更新使用它的所有文件/文件夹中的命名空间。只要您的命名空间一致,它应该获得与更改文件夹中所有命名空间相同的结果。

If your namespaces aren't consistant, and you're just tidying up then I'm afraid you've got a lot of clicking in front of you (or behind you as you've probably already done this).

如果您的命名空间不一致,而您只是在整理,那么恐怕您前面(或在您后面,因为您可能已经这样做了)有很多点击。