自动重构以将参数名称添加到方法调用 [英] Automated refactoring to add parameter names to method calls

查看:81
本文介绍了自动重构以将参数名称添加到方法调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在进行大量重构。

我有数十种方法,通过位置参数进行调用。现在,我想通过命名参数调用它们。这些方法存在于多个非继承类中,并且名称相同且签名不同。示例:

I have dozens of methods, which are called via positional parameters. Now I would like to have them called via named parameters. The methods exist in several, non-inherited classes and have the same name and their signatures differ. Example:

定义

public class Foo
{
    public static Foo Create(int count, string name)
    {
        ...
    }
}

public class Bar
{
    public static Bar Create(string description, bool yesNo, float factor)
    {
        ...
    }
}

以下我想替换的电话,来自

And the following calls I would like to replace, from

public void CreateSomeObjects()
{
    var foo = Foo.Create(123, "foo");
    var bar = Bar.Create("bar", true, 1.23);
}

public void CreateSomeObjects()
{
    var foo = Foo.Create(count: 123, name: "foo");
    var bar = Bar.Create(description: "bar", yesNo: true, factor: 1.23);
}

我使用Visual Studio Premium 2013和Resharper。任何想法如何实现这一目标? (我只需要一个提示,没有完整的解决方案。)

I use Visual Studio Premium 2013 and Resharper. Any ideas how to achieve this? (I just need a hint, no complete solution.)

推荐答案

不知道这有多实用,但是您可以使用ReSharper:

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


  1. 使用查找用法获取所有方法调用位置的列表。

  2. 对于每种用法,双击以转到该方法。

  3. 然后在代码编辑器中,单击一个参数值,ReSharper应该显示其动作指示器(左边缘)。

  4. 单击操作指示器以显示操作上下文菜单。

  5. 选择添加参数名称操作以将参数名称添加到所有参数。

  6. 重复。

  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.

这篇关于自动重构以将参数名称添加到方法调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆