.net c#重命名当前项目的所有名称空间

Renaming all namespaces of current project
2021-07-22
  •  译文(汉语)
  •  原文(英语)

我在一个项目上工作,我从一个命名空间开始,但是我想把到目前为止所做的一切都放到一个子命名空间(或更深)中,这样我就可以将"根"命名空间用于其他项目

例如:

Namespaces:
Foo
Foo.SubjectA
Foo.SubjectB

必须成为:

Foo.WhatEverIWantHere
Foo.WhatEverIWantHere.SubjectA
Foo.WhatEverIWantHere.SubjectB

另外,我已经将所有文件放入目标文件夹中,以便在解决方案资源管理器中重命名名称空间.

我正在寻找工具或正则表达式来快速替换.你能推荐什么?

速聊1:
我正在寻找工具或正则表达式来快速替换
速聊2:
Visual Studio"搜索并替换"可能非常有效.或下载Resharper试用版.Resharper对重命名空间具有强大的支持.
速聊3:
VS已经知道如何做到这一点.确保项目构建干净,并且您在源代码管理中拥有良好的副本.在文本编辑器中右键单击名称空间名称,"重构+重命名".单击更多以获取IDE的绳索,这应该是可以发现的.
解决过程1

右键单击要更改的名称空间:

  1. 转到重构选项
  2. 单击重命名
  3. 输入新名称,然后按确定

im working on a project, i started in a namespace, but i want to put everything i made so far into a sub namespace(or deeper) so i can use the 'root' namespace for other projects

exapmle:

Namespaces:
Foo
Foo.SubjectA
Foo.SubjectB

has to become:

Foo.WhatEverIWantHere
Foo.WhatEverIWantHere.SubjectA
Foo.WhatEverIWantHere.SubjectB

also I already put all the files into target folders for the namespace renaming in the solution explorer.

I'm looking for something like a tool, or a regex expression for quick-replace. What can you recommend?

Talk1:
Im looking for something like a tool, or a regex expression for quick-replace
Talk2:
Visual Studio "Search and replace" can be very effective. Or download a Resharper trial. Resharper has great support for renaming namespaces.
Talk3:
VS already knows how to do this. Ensure the project builds cleanly and you have it a good copy in source control. Right-click the namespace name in the text editor, Refactor + Rename. Click around some more to get the ropes of the IDE, this is supposed to be discoverable.
Solutions1

Right Click on the namespace you want to change:

  1. Go to refactor option
  2. Click on Rename
  3. Enter new Name and Press Ok
转载于:https://stackoverflow.com/questions/17362090/renaming-all-namespaces-of-current-project

本人是.net程序员,因为英语不行,使用工具翻译,希望对有需要的人有所帮助
如果本文质量不好,还请谅解,毕竟这些操作还是比较费时的,英语较好的可以看原文

留言回复
我们只提供高质量资源,素材,源码,坚持 下了就能用 原则,让客户花了钱觉得值
上班时间 : 周一至周五9:00-17:30 期待您的加入