vendredi 22 janvier 2021

Detect generic method parameter types

I have a MethodInfo of some generic method definition (e.g. IEnumerable<TResult> Select<TSource,TResult> (this IEnumerable<TSource> source, Func<TSource,int,TResult> selector)) and a list of parameter types IReadOnlyList<Type>. I need a method:

MethodInfo? DetectAndMakeGeneric(MethodInfo info, IReadOnlyList<Type> parameterTypes);

that will find if there is any possible specific combination for generic parameters so that I can call the method by using a list of parameters of specified types. If not possible, method should return null.

In other words something like C# compiler is doing to automatically resolve generic parameter from parameter types.





Aucun commentaire:

Enregistrer un commentaire