Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change method calls from Implicit type arguments to explicit

Tags:

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?

like image 559
Hristo Kolev Avatar asked Mar 27 '26 02:03

Hristo Kolev


1 Answers

I'm using Resharper 2017.2.2. Try the following steps and let me know how it works for you:

  1. Position your cursor on the call that is missing the generic type arguments. In your case it will be at the end of the method name, before the opening parenthesis:

    Editable|(source, destination);
            ^ the pipe in the above line is your cursor 
    
  2. Hit alt + enter to open the quick fix tool window.

  3. Locate the option named Insert inferred type arguments and expand the arrow to the right if you want to refactor at file, folder, project or solution level and click the desired option. Take a look at the below picture:

Insert inferred type arguments

  1. This should insert all the inferred type arguments for the selected level.

Hope this helps!

like image 105
Karel Tamayo Avatar answered Mar 29 '26 15:03

Karel Tamayo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!