Edit: I'm doing Reflection.Emit(opcode, MethodInfo)
There is a generic type G<T>, it is instantiated as e.g. G<int32> with a method M. (I don't know what type G will be in advance).
I'm given that MethodInfo of G<int32>.M. I want to get the original corresponding MethodInfo on the generic type definition which would have the different DeclaringType, G<T>.
Is there any simple and efficient way to do this?
The only way I can think of doing this is
Do G<int32>.GetGenericTypeDefinition() to get G<T>
Do GetMethods() on G<T>
Iterate through all the results and compare them to the original method in question.
It seems complex and like it would be really inefficient. From what I understand the two MethodInfos should have the same metadata token. Is there some better way?
View Complete Post