예제 #1
0
        //
        // Return a generic type instantiation using the runtime type system. If the underlying runtime type system does not support
        // this operation, return false.
        //
        internal bool TryLookupConstructedGenericTypeForComponents(GenericTypeLookupData lookupData, out RuntimeTypeHandle runtimeTypeHandle)
        {
            if (!TryGetStaticGenericTypeForComponents(lookupData, out runtimeTypeHandle))
            {
                if (!TryGetDynamicGenericTypeForComponents(lookupData, out runtimeTypeHandle))
                {
                    return(false);
                }
            }

            return(true);
        }
예제 #2
0
        internal unsafe bool TryGetStaticGenericTypeForComponents(GenericTypeLookupData lookupData, out RuntimeTypeHandle runtimeTypeHandle)
        {
            // Search the hashtable for a generic instantiation match
            // TODO multi-file: consider whether we can limit the search somehow,
            // i.e. not look at all the modules

            runtimeTypeHandle = default(RuntimeTypeHandle);

            int loadedModuleCount = RuntimeAugments.GetLoadedModules(null);
            var moduleHandles     = new System.IntPtr[loadedModuleCount];

            RuntimeAugments.GetLoadedModules(moduleHandles);

            NativeHashtable         genericsHashtable;
            ExternalReferencesTable externalReferencesLookup;

            foreach (IntPtr moduleHandle in moduleHandles)
            {
                if (!GetHashtableFromBlob(moduleHandle, ReflectionMapBlob.GenericsHashtable, out genericsHashtable, out externalReferencesLookup))
                {
                    continue;
                }

                int lookupHashcode = lookupData.LookupHashCode();
                var enumerator     = genericsHashtable.Lookup(lookupHashcode);

                NativeParser entryParser;
                while (!(entryParser = enumerator.GetNext()).IsNull)
                {
                    RuntimeTypeHandle tentativeType = externalReferencesLookup.GetRuntimeTypeHandleFromIndex(entryParser.GetUnsigned());

                    if (!lookupData.MatchParsedEntry(tentativeType))
                    {
                        continue;
                    }

                    runtimeTypeHandle = tentativeType;
                    Debug.Assert(RuntimeAugments.IsGenericType(runtimeTypeHandle));

                    return(true);
                }
            }

            return(false);
        }
예제 #3
0
        private unsafe bool TryGetDynamicGenericTypeForComponents(GenericTypeLookupData lookupData, out RuntimeTypeHandle runtimeTypeHandle)
        {
            runtimeTypeHandle = default(RuntimeTypeHandle);

            using (LockHolder.Hold(_dynamicGenericsLock))
            {
                GenericTypeEntry entry;
                if (!_dynamicGenericTypes.TryGetValue(lookupData, out entry))
                {
                    return(false);
                }

                if (!entry._isRegisteredSuccessfully)
                {
                    return(false);
                }

                runtimeTypeHandle = entry._instantiatedTypeHandle;
                return(true);
            }
        }