Próbuję wykryć czy dana instancja typu obiektu jest rodzajowy „IEnumerable” ...NET Reflection: Wykrywanie IEnumerable <T>
Najlepszym mogę wymyślić to:
// 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)
Ale wydaje się to nieco pośrednie - czy istnieje bardziej bezpośredni/elegancki sposób na zrobienie tego?
Proszę zobaczyć moje obserwacje: http://stackoverflow.com/questions/1650310/net-reflection-determinating-whether-an-array-of-t-would-be-convertible-to-some-o –