Exemple #1
0
        public MrType GetTypeFromEntityHandle(EntityHandle baseTypeEntityHandle, TypeDefinition typeDefinition)
        {
            var provider = new DisassemblingTypeProvider(this);

            switch (baseTypeEntityHandle.Kind)
            {
            case HandleKind.TypeDefinition:
            {
                var baseTypeDefinitionHandle = (TypeDefinitionHandle)baseTypeEntityHandle;
                //var baseTypeHandleWrapper = GetTypeFromEntityHandle(typeDefinition, baseTypeDefinitionHandle);
                var baseTypeHandleWrapper = MrType.CreateFromTypeDefinition(baseTypeDefinitionHandle, this);
                return(baseTypeHandleWrapper);
            }

            //case HandleKind.TypeDefinition:
            //    type = GetTypeOfTypeDef((TypeDefinitionHandle)token, out isNoPiaLocalType, isContainingType: false);
            //    break;

            case HandleKind.TypeSpecification:
            {
                var typeSpecification = Reader.GetTypeSpecification((TypeSpecificationHandle)baseTypeEntityHandle);


                var genericTypeParameters = typeDefinition
                                            .GetGenericParameters()
                                            .Select(h => MrType.CreateFromGenericParameterHandle(h, this))
                                            .ToImmutableArray();

                var context = new MRGenericContext(genericTypeParameters, ImmutableArray <MrType> .Empty);

                var mrType = typeSpecification.DecodeSignature(provider, context);
                return(mrType);
            }


            case HandleKind.TypeReference:
            {
                var referencedTypeDefinitionHandleWrapper = _loadContext.GetTypeFromReference(Reader, (TypeReferenceHandle)baseTypeEntityHandle);
                return(referencedTypeDefinitionHandleWrapper);
            }

            default:
                throw new Exception("Unknown entity type");
            }
        }
Exemple #2
0
        // This must be called after the LoadContext has loaded all the assemblies,
        // so that we know which referent types have to be faked.
        internal void Initialize()
        {
            if (IsFakeAssembly)
            {
                return;
            }

            TypeProvider = new DisassemblingTypeProvider(this);

            var assemblyReferenceHandles = Reader.AssemblyReferences;

            foreach (var assemblyReferenceHandle in assemblyReferenceHandles)
            {
                var assemblyReference      = Reader.GetAssemblyReference(assemblyReferenceHandle);
                var referencedAssemblyName = assemblyReference.GetAssemblyName().Name;

                _loadContext.LoadFromAssemblyName(referencedAssemblyName, implicitLoad: true);
            }

            // Get all the type names so that we can look up by name
            EnsureTypesAreLoaded();
        }