I have a generic method
public void Foo<T>(T arg) where T : ISomeInterface
This method is used quite a lot throughout the code, and I want to find where it is used with T being a specific type.
I can text-search for
"Foo<TheType>("
but most often the type argument has been omitted from the call (inferred). Is there any way I can find these method invocations in VS2010 or perhaps ReSharper?
The short answer is, that there is no way to find out the runtime type of generic type parameters in Java. I suggest reading the chapter about type erasure in the Java Tutorial for more details. A popular solution to this is to pass the Class of the type parameter into the constructor of the generic type, e.g.
The generic argument list is a comma-separated list of type arguments. A type argument is the name of an actual concrete type that replaces a corresponding type parameter in the generic parameter clause of a generic type. The result is a specialized version of that generic type.
Definition: “A generic type is a generic class or interface that is parameterized over types.” Essentially, generic types allow you to write a general, generic class (or method) that works with different types, allowing for code re-use.
In the next version of ReSharper, this will be covered by "Search with Pattern" feature. http://youtrack.jetbrains.net/issue/RSRP-288080
You could possibly get the compiler to help you find them using the old break-it-and-and-see-what-doesn't-compile approach: if the type T in question is your own code, try changing its definition so that it no longer implements ISomeInterface.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With