FindConstructedType() public static method

Finds a single constructed occurance of a specified generic definition in the specified type's inheritence hierarchy.
public static FindConstructedType ( IType type, IType definition ) : IType
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 IType
Exemplo n.º 1
0
        private bool InferConstructedType(IType formalType, IType actualType, TypeInference inference)
        {
            // look for a single occurance of the formal
            // constructed type in the actual type's hierarchy
            IType constructedActualType = GenericsServices.FindConstructedType(
                actualType,
                formalType.ConstructedInfo.GenericDefinition);

            if (constructedActualType == null)
            {
                return(false);
            }

            // Exact inference requires the constructed occurance to be
            // the actual type itself
            if (inference == TypeInference.Exact && actualType != constructedActualType)
            {
                return(false);
            }

            for (int i = 0; i < formalType.ConstructedInfo.GenericArguments.Length; ++i)
            {
                bool inferenceSuccessful = Infer(
                    formalType.ConstructedInfo.GenericArguments[i],
                    constructedActualType.ConstructedInfo.GenericArguments[i],
                    TypeInference.Exact);                     // Generic arguments must match exactly, no variance allowed

                if (!inferenceSuccessful)
                {
                    return(false);
                }
            }
            return(true);
        }