将方法调用从隐式类型参数更改为显式

Change method calls from Implicit type arguments to explicit

我有一个具有以下签名的方法:

 public static TDestination Editable<TSource, TDestination>
          (TSource source, TDestination destination)
    {
      ...
    }

像这样调用了数百次:

Editable(source, destination);

我想改成

Editable<TSource, TDestination>(source, destination);

这样做的原因是我希望能够获得调用此方法时实际使用的所有类型参数的列表,而不必检查每个调用站点。如果我可以在每个调用站点明确显示类型参数,我可以简单地搜索源代码 机械地获取传递给该方法的所有类型参数的列表。

我如何使用 ReSharper 或其他工具做到这一点?

我正在使用 Resharper 2017.2.2。请尝试以下步骤,让我知道它是如何为您服务的:

  1. 将光标定位在缺少泛型类型参数的调用上。在您的情况下,它将位于方法名称的末尾,左括号之前:

    Editable|(source, destination);
            ^ the pipe in the above line is your cursor 
    
  2. 按 alt + enter 打开快速修复工具 window。

  3. 找到名为 Insert inferred type arguments 的选项,如果要重构,则向右展开箭头在文件、文件夹、项目或解决方案级别,然后单击所需的选项。看看下面的图片:

  1. 这应该插入所选级别的所有推断类型参数。

希望对您有所帮助!