mercredi 26 avril 2017

How can I get the number of type parameters on an open generic in C#

In short this pretty much explains my problem ...

class Foo<T> { ... }
var type = typeof(Foo<>); <-- runtime provides a RuntimeType object instance in my real code
var paramCount = ((RuntimeType)type).GetGenericParameters().Count; <-- I need this

The problem of course is that "RuntimeType" is an internal type in (I believe) mscorlib, so I can't access it from my code.

Is there another / better way to do this?





Aucun commentaire:

Enregistrer un commentaire