Automated refactoring to add parameter names to method calls

て烟熏妆下的殇ゞ 提交于 2019-12-03 04:59:46

Not sure how practical this is but you can do the following using ReSharper:

  1. Use "Find Usages" to get a list of all method call locations.
  2. For each usage, double-click to go to the method.
  3. Then in the code editor, click on a parameter value and ReSharper should show its action indicator (a light bulb or hammer in the left margin).
  4. Click the action indicator to show the action context menu.
  5. Select the "Add argument name" action to add parameter names to all parameters.
  6. Repeat.

Years after this question was asked, I found it while Googling (as I'm in the same situation).

I don't have access to ReSharper, but for me, the excellent Roslynator was the solution.

You can install it through the VS2017/2019 Extensions and Updates dialog (search for "Roslynator"), or through the VS Marketplace. There is also a version which only contains the refactorings, if for some reason you don't want the analysers installed.

Once you've installed the extension and restarted Visual Studio, you can right-click the first parameter of any method and select Quick Actions and Refactorings..., then click Add argument name 'XXX' (including trailing arguments) to add in the names (see screen grabs below).

It's not completely automated (although being Roslyn-based I presume it could be), but I've already saved a lot of time with it.

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