How to find common calls with a specific type argument in my source?

I have a general method

public void Foo<T>(T arg) where T : ISomeInterface 

This method is used quite a lot in the whole code, and I want to find where it is used when T is a specific type.

I can text-search for

 "Foo<TheType>(" 

but most often the type argument was excluded from the call (inferred). Is there a way to find these method calls in VS2010 or maybe ReSharper?

+6
source share
6 answers

In the next version of ReSharper, this will be covered by the Search With Template feature. http://youtrack.jetbrains.net/issue/RSRP-288080

+4
source

You could get a compiler to help you find them using the old break-it-and-see-what-doesn't-compile method: if type T is your own code, try changing it so that it no longer implements ISomeInterface.

+1
source

Run the build through ildasm and find the appropriate method signature, then reverse the operation through disassembly to get the source file and line number.

0
source

I tried to execute the ReSharper search pattern (ReSharper-> Tools-> PatternCatalog-> Add Pattern):

Search Pattern: Foo ($ arg $)
Placeholder: arg = expression that is of type TheType

Then save it and click "Find Now."

0
source

Temporarily declare a non-generic method and find its use.

 public void Foo(TheType arg) { } 

After the declaration, the preferred method instead of the general one.

0
source

As you already mentioned, you can use text search for " Foo<TheType>( " and " Foo(TheType ", where it is displayed

-1
source

Source: https://habr.com/ru/post/907204/


All Articles