I'm using the following method but on a Dictionary it returns the TKey. Dictionary implements ICollection<KeyValuePair<TKey,TValue>> so how can i get KeyValuePair<TKey,TValue>?
public static Type GetCollectionGenericType( this Type type )
{
foreach( Type interfaceType in type.GetInterfaces() )
{
if( interfaceType.IsGenericType &&
interfaceType.GetGenericTypeDefinition() == typeof( ICollection<> ) )
{
return type.GetGenericArguments()[ 0 ];
}
}
return null;
}
Aucun commentaire:
Enregistrer un commentaire