Ejemplo n.º 1
0
        private MethodSignature InitializeSignature()
        {
            var metadataReader = MetadataReader;

            NativeFormatSignatureParser parser = new NativeFormatSignatureParser(MetadataUnit, MetadataReader.GetMethod(_handle).Signature, metadataReader);
            var signature = parser.ParseMethodSignature();
            return (_signature = signature);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Use for handle kinds, TypeInstantiationSignature, TypeSpecification, SZArraySignature, ArraySignature, PointerSignature, ByReferenceSignature, TypeVariableSignature, MethodTypeVariableSignature
        /// </summary>
        /// <returns></returns>
        public TypeDesc ParseTypeSignature()
        {
            switch (_signatureHandle.HandleType)
            {
                case HandleType.TypeSpecification:
                    {
                        var typeSpec = _metadataReader.GetTypeSpecification(_signatureHandle.ToTypeSpecificationHandle(_metadataReader));
                        return _metadataUnit.GetType(typeSpec.Signature);
                    }

                case HandleType.TypeInstantiationSignature:
                    {
                        var typeInstantiationSignature = _metadataReader.GetTypeInstantiationSignature(_signatureHandle.ToTypeInstantiationSignatureHandle(_metadataReader));
                        var openType = (MetadataType)_metadataUnit.GetType(typeInstantiationSignature.GenericType);
                        var typeArguments = typeInstantiationSignature.GenericTypeArguments;
                        TypeDesc[] instantiationArguments = new TypeDesc[typeArguments.Count];
                        int i = 0;
                        foreach (Handle typeArgument in typeArguments)
                        {
                            instantiationArguments[i] = _metadataUnit.GetType(typeArgument);
                            i++;
                        }
                        return _metadataUnit.Context.GetInstantiatedType(openType, new Instantiation(instantiationArguments));
                    }

                case HandleType.SZArraySignature:
                    {
                        var szArraySignature = _metadataReader.GetSZArraySignature(_signatureHandle.ToSZArraySignatureHandle(_metadataReader));
                        return _metadataUnit.Context.GetArrayType(_metadataUnit.GetType(szArraySignature.ElementType));
                    }

                case HandleType.ArraySignature:
                    {
                        var arraySignature = _metadataReader.GetArraySignature(_signatureHandle.ToArraySignatureHandle(_metadataReader));
                        return _metadataUnit.Context.GetArrayType(_metadataUnit.GetType(arraySignature.ElementType), arraySignature.Rank);
                    }

                case HandleType.PointerSignature:
                    {
                        var pointerSignature = _metadataReader.GetPointerSignature(_signatureHandle.ToPointerSignatureHandle(_metadataReader));
                        return _metadataUnit.Context.GetPointerType(_metadataUnit.GetType(pointerSignature.Type));
                    }

                case HandleType.ByReferenceSignature:
                    {
                        var byReferenceSignature = _metadataReader.GetByReferenceSignature(_signatureHandle.ToByReferenceSignatureHandle(_metadataReader));
                        return _metadataUnit.Context.GetByRefType(_metadataUnit.GetType(byReferenceSignature.Type));
                    }

                case HandleType.TypeVariableSignature:
                    {
                        var typeVariableSignature = _metadataReader.GetTypeVariableSignature(_signatureHandle.ToTypeVariableSignatureHandle(_metadataReader));
                        return _metadataUnit.Context.GetSignatureVariable(typeVariableSignature.Number, false);
                    }

                case HandleType.MethodTypeVariableSignature:
                    {
                        var methodVariableSignature = _metadataReader.GetMethodTypeVariableSignature(_signatureHandle.ToMethodTypeVariableSignatureHandle(_metadataReader));
                        return _metadataUnit.Context.GetSignatureVariable(methodVariableSignature.Number, true);
                    }

                case HandleType.FunctionPointerSignature:
                    {
                        var functionPointerSignature = _metadataReader.GetFunctionPointerSignature(_signatureHandle.ToFunctionPointerSignatureHandle(_metadataReader));
                        NativeFormatSignatureParser methodSigParser = new NativeFormatSignatureParser(_metadataUnit, functionPointerSignature.Signature, _metadataReader);
                        return _metadataUnit.Context.GetFunctionPointerType(methodSigParser.ParseMethodSignature());
                    }
                default:
                    throw new BadImageFormatException();
            }
        }