FindConstructedTypes() public static method

Finds types constructed from the specified definition in the specified type's interfaces and base types.
public static FindConstructedTypes ( IType type, IType definition ) : IEnumerable
type IType The type in whose hierarchy to search for constructed types.
definition IType The generic type definition whose constructed versions to search for.
return IEnumerable
Beispiel #1
0
        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);
        }