Mass renaming (refactoring) in C# project [closed]

别说谁变了你拦得住时间么 提交于 2019-12-24 06:33:52

问题


Today, I received an excel file with two columns. I have to rename objects in a solution according to excel file.

First column contains "current name", second column contains "new name". More than 5000 lines there.

Currently it is VS2013 with Resharper, C# solution contains several projects.

How can I automate this process?


回答1:


Unfortunately recent versions of Visual Studio have lost macros (essentially: not enough people using them). Thus the easiest path is unavailable.

As the other answer notes (now deleted), doing this one name at a time with existing VS tools is possible, but clearly infeasible for 5000!

I would approach this by:

  1. Look for other tools, even if they have a price the time saved is likely to be significant. If nothing found, try #2. Given a few months Rosalyn might be an option (or even a preview of it: you won't be putting this into production with customers I assume!).

  2. Put together a simple search and replace in a script tool (eg. PowerShell: advantage of having access to the full .NET framework and inbuilt CSV support) to perform one substitution (and you'll need to decide to include or exclude comments and strings). Then repeat that for each renaming.

#2 is likely to need to few tries: false positives will be all too easy.



来源:https://stackoverflow.com/questions/20972666/mass-renaming-refactoring-in-c-sharp-project

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!