I'm trying to detect if a particular instance of a Type object is a generic "IEnumerable"...
The best I can come up with is:
// 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)
But this seems a bit indirect - is there a more direct/elegant way to do this?