public IType GetGenericEnumerableItemType(IType iteratorType)
{
// Arrays implicitly implement IEnumerable[of element type]
if (iteratorType is ArrayType) return iteratorType.ElementType;
// If type is not an array, try to find IEnumerable[of some type] in its interfaces
IType itemType = null;
foreach (IType type in GenericsServices.FindConstructedTypes(iteratorType, IEnumerableGenericType))
{
IType candidateItemType = type.ConstructedInfo.GenericArguments[0];
if (itemType != null)
itemType = GetMostGenericType(itemType, candidateItemType);
else
itemType = candidateItemType;
}
return itemType;
}