2010-10-14 13 views
7

Sono curioso di sapere se il tipo dato è chiuso versione di tipo aperto. Per esempioConfronta tipo chiuso con tipo aperto

public bool IsGenericList(Type source) 
{ 
    return (source.IsGenericType && 
      /*here goes the manipulation on source type*/ == typeof(List<>)); 
} 

risposta

13

Prova Type.GetGenericTypeDefinition:

public bool IsGenericList(Type source) 
{ 
    return source.IsGenericType && 
      source.GetGenericTypeDefinition() == typeof(List<>); 
} 
+0

Questo è ciò che avevo provato in primo luogo, ma ho pensato che non funziona perché avevo bug da qualche altra parte nel codice. Grazie comunque :) – jethro

Problemi correlati