Пример #1
0
            protected sealed override RuntimeGenericParameterTypeForTypes Factory(RuntimeGenericParameterTypeForTypes.UnificationKey key)
            {
                RuntimeNamedTypeInfo typeOwner = RuntimeNamedTypeInfo.GetRuntimeNamedTypeInfo(key.Reader, key.TypeDefinitionHandle);

                return(new RuntimeGenericParameterTypeForTypes(key.Reader, key.GenericParameterHandle, typeOwner));
            }
Пример #2
0
        //
        // Main routine to resolve a typeReference.
        //
        private static RuntimeType TryResolveTypeReference(this ReflectionDomain reflectionDomain, MetadataReader reader, TypeReferenceHandle typeReferenceHandle, ref Exception exception)
        {
            {
                ExecutionDomain executionDomain = reflectionDomain as ExecutionDomain;
                if (executionDomain != null)
                {
                    RuntimeTypeHandle resolvedRuntimeTypeHandle;
                    if (executionDomain.ExecutionEnvironment.TryGetNamedTypeForTypeReference(reader, typeReferenceHandle, out resolvedRuntimeTypeHandle))
                    {
                        return(ReflectionCoreNonPortable.GetTypeForRuntimeTypeHandle(resolvedRuntimeTypeHandle));
                    }
                }
            }

            TypeReference typeReference = typeReferenceHandle.GetTypeReference(reader);
            String        name          = typeReference.TypeName.GetString(reader);
            Handle        parent        = typeReference.ParentNamespaceOrType;
            HandleType    parentType    = parent.HandleType;
            TypeInfo      outerTypeInfo = null;

            // Check if this is a reference to a nested type.

            if (parentType == HandleType.TypeDefinition)
            {
                outerTypeInfo = RuntimeNamedTypeInfo.GetRuntimeNamedTypeInfo(reader, parent.ToTypeDefinitionHandle(reader));
            }
            else if (parentType == HandleType.TypeReference)
            {
                RuntimeType outerType = reflectionDomain.TryResolveTypeReference(reader, parent.ToTypeReferenceHandle(reader), ref exception);
                if (outerType == null)
                {
                    return(null);
                }
                outerTypeInfo = outerType.GetTypeInfo();   // Since we got to outerType via a metadata reference, we're assured GetTypeInfo() won't throw a MissingMetadataException.
            }
            if (outerTypeInfo != null)
            {
                // It was a nested type. We've already resolved the containing type recursively - just find the nested among its direct children.
                TypeInfo resolvedTypeInfo = outerTypeInfo.GetDeclaredNestedType(name);
                if (resolvedTypeInfo == null)
                {
                    exception = reflectionDomain.CreateMissingMetadataException(outerTypeInfo, name);
                    return(null);
                }
                return((RuntimeType)(resolvedTypeInfo.AsType()));
            }


            // If we got here, the typeReference was to a non-nested type.
            if (parentType == HandleType.NamespaceReference)
            {
                AssemblyQualifiedTypeName assemblyQualifiedTypeName = parent.ToNamespaceReferenceHandle(reader).ToAssemblyQualifiedTypeName(name, reader);
                RuntimeType runtimeType;
                exception = assemblyQualifiedTypeName.TryResolve(reflectionDomain, null, /*ignoreCase: */ false, out runtimeType);
                if (exception != null)
                {
                    return(null);
                }
                return(runtimeType);
            }

            throw new BadImageFormatException(); // Expected TypeReference parent to be typeRef, typeDef or namespaceRef.
        }
 internal RuntimeTypeInfo GetInspectionOnlyNamedRuntimeTypeInfo()
 {
     return(RuntimeNamedTypeInfo.GetRuntimeNamedTypeInfo(_reader, _typeDefinitionHandle));
 }
Пример #4
0
 public static RuntimeTypeInfo GetNamedType(this TypeDefinitionHandle typeDefinitionHandle, MetadataReader reader, RuntimeTypeHandle precomputedTypeHandle)
 {
     return(RuntimeNamedTypeInfo.GetRuntimeNamedTypeInfo(reader, typeDefinitionHandle, precomputedTypeHandle: precomputedTypeHandle));
 }