J'essaie de détecter si une instance particulière d'un objet type est un « IEnumerable » générique ...Réflexion .NET: Détection IEnumerable <T>
Le meilleur que je peux trouver est:
// theType might be typeof(IEnumerable<string>) for example... or it might not
bool isGenericEnumerable = theType.GetGenericTypeDefinition() == typeof(IEnumerable<object>).GetGenericTypeDefinition()
if(isGenericEnumerable)
{
Type enumType = theType.GetGenericArguments()[0];
etc. ...// enumType is now typeof(string)
Mais cela semble un peu indirect - existe-t-il un moyen plus direct/élégant de le faire?
s'il vous plaît voir mon suivi: http://stackoverflow.com/questions/1650310/net-reflection-determining-whether-an-array-of-t-would-be-convertible-to-some-o –