public unsafe static bool TryGetTypeReferenceForNamedType(RuntimeTypeHandle runtimeTypeHandle, out MetadataReader metadataReader, out TypeReferenceHandle typeRefHandle)
        {
            // Iterate over all modules, starting with the module that defines the EEType
            foreach (IntPtr moduleHandle in ModuleList.Enumerate(RuntimeAugments.GetModuleFromTypeHandle(runtimeTypeHandle)))
            {
                MetadataTable mapTable = MetadataTable.CreateTypeMapTable(moduleHandle);
                foreach (var ptrEntry in mapTable)
                {
                    var pCurrentEntry = (TypeMapEntry *)ptrEntry;
                    RuntimeTypeHandle entryTypeHandle     = RuntimeAugments.CreateRuntimeTypeHandle(pCurrentEntry->EEType);
                    Handle            entryMetadataHandle = pCurrentEntry->TypeDefinitionHandle.AsHandle();
                    if (entryTypeHandle.Equals(runtimeTypeHandle) &&
                        entryMetadataHandle.HandleType == HandleType.TypeReference)
                    {
                        metadataReader = ModuleList.Instance.GetMetadataReaderForModule(moduleHandle);
                        typeRefHandle  = entryMetadataHandle.ToTypeReferenceHandle(metadataReader);
                        return(true);
                    }
                }
            }

            metadataReader = null;
            typeRefHandle  = default(TypeReferenceHandle);

            return(false);
        }
Example #2
0
 internal Enumerator(ref MetadataTable table)
 {
     _base        = table._blob;
     _elementSize = table._elementSize;
     _current     = _base - _elementSize;
     _limit       = _base + (_elementSize * table.ElementCount);
 }
        public unsafe bool TryGetNamedTypeForMetadata(MetadataReader metadataReader, TypeDefinitionHandle typeDefHandle, out RuntimeTypeHandle runtimeTypeHandle)
        {
            IntPtr        moduleHandle = ModuleList.Instance.GetModuleForMetadataReader(metadataReader);
            MetadataTable mapTable     = MetadataTable.CreateTypeMapTable(moduleHandle);

            foreach (var ptrEntry in mapTable)
            {
                TypeMapEntry *pCurrentEntry = (TypeMapEntry *)ptrEntry;
                if (pCurrentEntry->TypeDefinitionHandle.AsHandle().Equals(typeDefHandle))
                {
                    runtimeTypeHandle = RuntimeAugments.CreateRuntimeTypeHandle(pCurrentEntry->EEType);
                    return(true);
                }
            }

            runtimeTypeHandle = default(RuntimeTypeHandle);
            return(false);
        }