Change method calls from Implicit type arguments to explicit

时间:2017-10-30 15:32:48

标签: c# resharper

I have a method with the following signature:

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

It is called hundreds of times like this:

Editable(source, destination);

I want to change it to

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

The reason for this is that I want to be able to get a list of all the type parameters that are actually used in calls to this method, without having to inspect each call site. If I could make the type parameters explicit at every call site, I could simply search the source code mechanically to get a list of all the type parameters that get passed to the method.

How can I do that with ReSharper, or another tool?

1 个答案:

答案 0 :(得分:2)

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

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

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

  3. 找到名为 插入推断类型参数 的选项,如果要在文件,文件夹,项目或解决方案级别重构,请展开右侧的箭头单击所需的选项。请看下面的图片:

  4. Insert inferred type arguments

    1. 这应该插入所选级别的所有推断类型参数。
    2. 希望这有帮助!