コード例 #1
0
        // Create a TypeSystem.MethodSignature object from a RuntimeSignature that isn't a NativeLayoutSignature
        private TypeSystem.MethodSignature TypeSystemSigFromRuntimeSignature(TypeSystemContext context, RuntimeSignature signature)
        {
            Debug.Assert(!signature.IsNativeLayoutSignature);

            ModuleInfo module = signature.GetModuleInfo();

#if ECMA_METADATA_SUPPORT
            if (module is NativeFormatModuleInfo)
#endif
            {
                NativeFormatModuleInfo nativeFormatModule = (NativeFormatModuleInfo)module;
                var metadataReader = nativeFormatModule.MetadataReader;
                var methodHandle   = signature.Token.AsHandle().ToMethodHandle(metadataReader);
                var metadataUnit   = ((TypeLoaderTypeSystemContext)context).ResolveMetadataUnit(nativeFormatModule);
                var parser         = new Internal.TypeSystem.NativeFormat.NativeFormatSignatureParser(metadataUnit, metadataReader.GetMethod(methodHandle).Signature, metadataReader);
                return(parser.ParseMethodSignature());
            }
#if ECMA_METADATA_SUPPORT
            else
            {
                EcmaModuleInfo             ecmaModuleInfo = (EcmaModuleInfo)module;
                TypeSystem.Ecma.EcmaModule ecmaModule     = context.ResolveEcmaModule(ecmaModuleInfo);
                var        ecmaHandle = System.Reflection.Metadata.Ecma335.MetadataTokens.EntityHandle(signature.Token);
                MethodDesc ecmaMethod = ecmaModule.GetMethod(ecmaHandle);
                return(ecmaMethod.Signature);
            }
#endif
        }
コード例 #2
0
        public uint GetGenericArgumentCountFromMethodNameAndSignature(MethodNameAndSignature signature)
        {
            if (signature.Signature.IsNativeLayoutSignature)
            {
                NativeReader reader = GetNativeLayoutInfoReader(signature.Signature);
                NativeParser parser = new NativeParser(reader, signature.Signature.NativeLayoutOffset);

                return(GetGenericArgCountFromSig(parser));
            }
            else
            {
                ModuleInfo module = signature.Signature.GetModuleInfo();

#if ECMA_METADATA_SUPPORT
                if (module is NativeFormatModuleInfo)
#endif
                {
                    NativeFormatModuleInfo nativeFormatModule = (NativeFormatModuleInfo)module;
                    var metadataReader = nativeFormatModule.MetadataReader;
                    var methodHandle   = signature.Signature.Token.AsHandle().ToMethodHandle(metadataReader);

                    var method          = methodHandle.GetMethod(metadataReader);
                    var methodSignature = method.Signature.GetMethodSignature(metadataReader);
                    return(checked ((uint)methodSignature.GenericParameterCount));
                }
#if ECMA_METADATA_SUPPORT
                else
                {
                    EcmaModuleInfo ecmaModuleInfo = (EcmaModuleInfo)module;
                    var            metadataReader = ecmaModuleInfo.MetadataReader;
                    var            ecmaHandle     = (System.Reflection.Metadata.MethodDefinitionHandle)System.Reflection.Metadata.Ecma335.MetadataTokens.Handle(signature.Signature.Token);
                    var            method         = metadataReader.GetMethodDefinition(ecmaHandle);
                    var            blobHandle     = method.Signature;
                    var            blobReader     = metadataReader.GetBlobReader(blobHandle);
                    byte           sigByte        = blobReader.ReadByte();
                    if ((sigByte & (byte)System.Reflection.Metadata.SignatureAttributes.Generic) == 0)
                    {
                        return(0);
                    }
                    uint genArgCount = checked ((uint)blobReader.ReadCompressedInteger());
                    return(genArgCount);
                }
#endif
            }
        }
コード例 #3
0
        /// <summary>
        /// Locate the containing module for a given metadata reader. Assert when not found.
        /// </summary>
        /// <param name="reader">Metadata reader to look up</param>
        /// <returns>Module handle of the module containing the given reader</returns>
        public static EcmaModuleInfo GetModuleInfoForMetadataReader(this ModuleList moduleList, MetadataReader reader)
        {
            foreach (ModuleInfo moduleInfo in moduleList.GetLoadedModuleMapInternal().Modules)
            {
                EcmaModuleInfo ecmaModuleInfo = moduleInfo as EcmaModuleInfo;
                if (ecmaModuleInfo == null)
                {
                    continue;
                }

                if (ecmaModuleInfo.MetadataReader == reader)
                {
                    return(ecmaModuleInfo);
                }
            }

            // We should never have a reader that is not associated with a module (where does it come from?!)
            Debug.Assert(false);
            return(null);
        }
コード例 #4
0
        internal bool IsStaticMethodSignature(RuntimeSignature methodSig)
        {
            if (methodSig.IsNativeLayoutSignature)
            {
                NativeReader reader = GetNativeLayoutInfoReader(methodSig);
                NativeParser parser = new NativeParser(reader, methodSig.NativeLayoutOffset);

                MethodCallingConvention callingConvention = (MethodCallingConvention)parser.GetUnsigned();
                return(callingConvention.HasFlag(MethodCallingConvention.Static));
            }
            else
            {
                ModuleInfo module = methodSig.GetModuleInfo();

#if ECMA_METADATA_SUPPORT
                if (module is NativeFormatModuleInfo)
#endif
                {
                    NativeFormatModuleInfo nativeFormatModule = (NativeFormatModuleInfo)module;
                    var metadataReader = nativeFormatModule.MetadataReader;
                    var methodHandle   = methodSig.Token.AsHandle().ToMethodHandle(metadataReader);

                    var method = methodHandle.GetMethod(metadataReader);
                    return((method.Flags & MethodAttributes.Static) != 0);
                }
#if ECMA_METADATA_SUPPORT
                else
                {
                    EcmaModuleInfo ecmaModuleInfo = (EcmaModuleInfo)module;
                    var            metadataReader = ecmaModuleInfo.MetadataReader;
                    var            ecmaHandle     = (System.Reflection.Metadata.MethodDefinitionHandle)System.Reflection.Metadata.Ecma335.MetadataTokens.Handle(methodSig.Token);
                    var            method         = metadataReader.GetMethodDefinition(ecmaHandle);
                    var            blobHandle     = method.Signature;
                    var            blobReader     = metadataReader.GetBlobReader(blobHandle);
                    byte           sigByte        = blobReader.ReadByte();
                    return((sigByte & (byte)System.Reflection.Metadata.SignatureAttributes.Instance) == 0);
                }
#endif
            }
        }
コード例 #5
0
        public override ModuleDesc ResolveAssembly(System.Reflection.AssemblyName name, bool throwErrorIfNotFound)
        {
#if SUPPORTS_NATIVE_METADATA_TYPE_LOADING
            AssemblyBindResult bindResult;
            Exception          failureException;
            if (!AssemblyBinderImplementation.Instance.Bind(name, out bindResult, out failureException))
            {
                if (throwErrorIfNotFound)
                {
                    throw failureException;
                }
                return(null);
            }

            var moduleList = Internal.Runtime.TypeLoader.ModuleList.Instance;

            if (bindResult.Reader != null)
            {
                NativeFormatModuleInfo   primaryModule = moduleList.GetModuleInfoForMetadataReader(bindResult.Reader);
                NativeFormatMetadataUnit metadataUnit  = ResolveMetadataUnit(primaryModule);
                return(metadataUnit.GetModule(bindResult.ScopeDefinitionHandle));
            }
#if ECMA_METADATA_SUPPORT
            else if (bindResult.EcmaMetadataReader != null)
            {
                EcmaModuleInfo ecmaModule = moduleList.GetModuleInfoForMetadataReader(bindResult.EcmaMetadataReader);
                return(ResolveEcmaModule(ecmaModule));
            }
#endif
            else
            {
                // Should not be possible to reach here
                throw new Exception();
            }
#else
            return(null);
#endif
        }