How to reformat naming styles with ReSharper?

可紊 提交于 2019-12-17 20:45:03

问题


I have several pages of code that need to have naming styles reinforced, e.g. use fooBar instead of FooBar for local variables. I don't want to correct it one by one for an obvious reason.

I tried to fiddle with the code cleanup profiles accessiable via ReSharper > Tools > Cleanup Code > Edit Profiles. I am not able to find a way to correct all naming style in one hit, or even with a keyboard shortcut. Could seasonsed ReSharper users advise how I can tackle this problem?


回答1:


I don't believe ReSharper has a way to do a bulk rename like you want. Changing the C# Naming Styles will certainly highlight (as warnings) those local variables that need changing, but Code Cleanup won't correct them for you.

There are times when renaming a variable to match a convention might result in one symbol colliding with another symbol that already exists; I imagine that's why ReSharper doesn't allow the bulk rename.

Two ReSharper shortcuts may make this pretty quick (and this is assuming you have adopted ReSharper's shortcut keys for Visual Studio):

  1. Alt + PgDn - Go to next highlight (error, warning or suggestion). This will let you get from one misnamed variable to the next quite quickly.
  2. Alt + Enter - Open the "Quick Fix" menu and select "Rename...". This will rename the variable and update all references.



回答2:


Starting from R# 8, there's the option to fix an issue in scope.

  1. Go to any occurrence of this issue
  2. Put the cursor on it
  3. Show potential fixes (CTRL+.)
  4. Select the first option 'Rename to xxx' and select 'fix naming in solution'

More info




回答3:


R# has an SDK. Perhaps you can add a cleanup option via this:

http://confluence.jetbrains.com/display/NETCOM/2.07+Code+Cleanup+%28R8%29

(I'm doing a mass naming refactor as well, but have only just started looking into writing something in their API. Don't know if this will work yet, or the effort involved.)




回答4:


Its included in resharper 2018, find an occurence of the incorrectly named variable, use the resharper context menu to fix all occurrence in the solution.



来源:https://stackoverflow.com/questions/6433654/how-to-reformat-naming-styles-with-resharper

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