lundi 9 mai 2016

Find T type of runtime IEnumerable when T is a generic type

I'm creating a deserializer that recieves a type and tries to find out if it's IEnumerable<T> to convert from a string representation to an object.

If T is a non-generic type, such as string, object or MyType, I can obtain the type from type.GetGenericArguments().First().

But if T is a generic type, such as KeyValuePair<K, V>, then calling type.GetGenericArguments().First() returns the type of K, which is indeed the first generic argument. I need to get the type of KeyValuePair<K, V> with K and V known at runtime.





Aucun commentaire:

Enregistrer un commentaire