This project is read-only.

Getting non-specific methods from generic types

Topics: Metadata Model
Jun 27, 2014 at 3:22 AM
Suppose I have two IMethodReferences - one for List<int>.Add(int) and one for List<double>.Add(double).

How can I get the generic version of these methods (List<T>.Add(T)) so that I can see that they are versions of the same method?

I see that such methods are contained in a generic type with tokens, and I can get the generic containing type (List<T>), but the methods themselves are not considered generic - they're just Add(int) and Add(double) so I haven't been able to figure out how to map them back to Add(T). But when I look at the IL I'm getting the references from (they're the targets of call operations) in ILDasm, I see that the calls are actually to generic versions of the methods, so it should be possible to get what I'm looking for.

I suppose I could always consult method tables for methods on the generic containing type that match the name and number of parameters, but that seems like a lot of work for something that should be simple (getting List<T> from List<int> is a single property call; getting .Add(T) from .Add(int) doesn't seem so different).

Thanks in advance!
Jun 27, 2014 at 4:13 AM
The methods are not generic as such. In CCI terms they are ISpecializedMethodReference objects. If you cast them down that interface, the UnspecializedVersion property will point you to the List<T>.Add(T) method.
Marked as answer by MJRousos on 6/27/2014 at 9:01 AM
Jun 27, 2014 at 5:01 PM
Ah, perfect; thanks, Herman!