Example #1
0
        public ModuleToken GetModuleTokenForType(EcmaType type, bool throwIfNotFound = true)
        {
            if (_compilationModuleGroup.VersionsWithType(type))
            {
                return(new ModuleToken(type.EcmaModule, (mdToken)MetadataTokens.GetToken(type.Handle)));
            }

            ModuleToken token;

            if (_typeToRefTokens.TryGetValue(type, out token))
            {
                return(token);
            }

            // If the token was not lazily mapped, search the input compilation set for a type reference token
            if (_compilationModuleGroup.TryGetModuleTokenForExternalType(type, out token))
            {
                return(token);
            }

            // Reverse lookup failed
            if (throwIfNotFound)
            {
                throw new NotImplementedException(type.ToString());
            }
            else
            {
                return(default(ModuleToken));
            }
        }
Example #2
0
        public ModuleToken GetModuleTokenForType(EcmaType type, bool allowDynamicallyCreatedReference, bool throwIfNotFound = true)
        {
            if (_compilationModuleGroup.VersionsWithType(type))
            {
                return(new ModuleToken(type.EcmaModule, (mdToken)MetadataTokens.GetToken(type.Handle)));
            }

            ModuleToken token;

            if (_typeToRefTokens.TryGetValue(type, out token))
            {
                return(token);
            }

            // If the token was not lazily mapped, search the input compilation set for a type reference token
            if (_compilationModuleGroup.TryGetModuleTokenForExternalType(type, out token))
            {
                return(token);
            }

            // If that didn't work, it may be in the manifest module used for version resilient cross module inlining
            if (allowDynamicallyCreatedReference)
            {
                var handle = _manifestMutableModule.TryGetExistingEntityHandle(type);

                if (handle.HasValue)
                {
                    return(new ModuleToken(_manifestMutableModule, handle.Value));
                }
            }

            // Reverse lookup failed
            if (throwIfNotFound)
            {
                throw new NotImplementedException(type.ToString());
            }
            else
            {
                return(default(ModuleToken));
            }
        }
Example #3
0
        public ModuleToken GetModuleTokenForType(EcmaType type, bool throwIfNotFound = true)
        {
            if (_compilationModuleGroup.ContainsType(type))
            {
                return(new ModuleToken(type.EcmaModule, (mdToken)MetadataTokens.GetToken(type.Handle)));
            }

            ModuleToken token;

            if (_typeToRefTokens.TryGetValue(type, out token))
            {
                return(token);
            }

            // Reverse lookup failed
            if (throwIfNotFound)
            {
                throw new NotImplementedException(type.ToString());
            }
            else
            {
                return(default(ModuleToken));
            }
        }
Example #4
0
 // Format helpers for future use
 // The idea is to improve formatting string with tokens value i.e.:
 // [Assembly]Class(0x1234) vs current [Assembly]Class
 // in case somebody will pass '--tokens' switch to ILVerify
 private string Format(EcmaType type)
 {
     return(type.ToString());
 }