Unfortunately, System.Reflection does not provide a good way to map a method of the constructed type to the corresponding method of determining the general type from which it was created. There are two solutions that I know of, none of them are perfect:
№1: static TypeBuilder.GetMethod. GetMethod TypeBuilder, generic built type MethodInfo
. TypeBuilder.GetMethod(Foo<int>, Foo<T>.Bar(T)) Foo<int>.Bar(T-as-int), Foo<int>.Bar(int).
( , , Foo<int> Foo<T>.Bar(T) Type MethodInfo, , ).
, , - TypeBuilder, .
№2: MetadataToken.. , Token . , Foo<T>.Bar(T) Foo<int>.Bar(T-as-int) Token. :
var barWithGenericParameterInfo = typeof(Foo<>).GetMethods()
.Where(mi => mi.Name == "Bar" &&
mi.GetParameters()[0].ParameterType.IsGenericParameter);
var mappedBarInfo = foo.GetType().GetMethods()
.Where(mi => mi.MetadataToken == genericBarInfo.MetadataToken);
( , :))
, MetadataToken (, ), . , .