I have the ISymbol object for an enumerable collection and need to get the underlying type.
e.g.
List<int> intList;
I have the ISymbol for intList, and need to find the underlying type - in this case, it is int.
I tried using the code listed here, but seems like reflection does not work here.
Here's my code snippet:
private Type GetUnderlyingTypeFromEnumerable(ISymbol symbol)
{
Type eType = null;
Type[] interfaces = symbol.GetType().GetInterfaces();
foreach (Type i in interfaces)
if (i.IsGenericType && i.GetGenericTypeDefinition().Equals(typeof(IEnumerable<>)))
{
eType = i.GetGenericArguments()[0];
break;
}
return eType;
}