Boo.Lang.Compiler.TypeSystem.Generics.GenericsServices.FindConstructedType C# (CSharp) Метод

FindConstructedType() публичный статический Метод

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.
Результат IType
        public static IType FindConstructedType(IType type, IType definition)
        {
            IType result = null;
            foreach (IType candidate in FindConstructedTypes(type, definition))
            {
                if (result == null) result = candidate;
                else if (result != candidate) return null;
            }
            return result;
        }

Usage Example

Пример #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);
        }