コード例 #1
0
        void Write(DataWriter writer, IList <PdbImport> imports)
        {
            int count = imports.Count;

            for (int i = 0; i < count; i++)
            {
                var import = imports[i];
                if (!ImportDefinitionKindUtils.ToImportDefinitionKind(import.Kind, out uint rawKind))
                {
                    helper.Error2("Unknown import definition kind: {0}.", import.Kind);
                    return;
                }
                writer.WriteCompressedUInt32(rawKind);
                switch (import.Kind)
                {
                case PdbImportDefinitionKind.ImportNamespace:
                    // <import> ::= ImportNamespace <target-namespace>
                    writer.WriteCompressedUInt32(WriteUTF8(((PdbImportNamespace)import).TargetNamespace));
                    break;

                case PdbImportDefinitionKind.ImportAssemblyNamespace:
                    // <import> ::= ImportAssemblyNamespace <target-assembly> <target-namespace>
                    writer.WriteCompressedUInt32(systemMetadata.GetToken(((PdbImportAssemblyNamespace)import).TargetAssembly).Rid);
                    writer.WriteCompressedUInt32(WriteUTF8(((PdbImportAssemblyNamespace)import).TargetNamespace));
                    break;

                case PdbImportDefinitionKind.ImportType:
                    // <import> ::= ImportType <target-type>
                    writer.WriteCompressedUInt32(GetTypeDefOrRefEncodedToken(((PdbImportType)import).TargetType));
                    break;

                case PdbImportDefinitionKind.ImportXmlNamespace:
                    // <import> ::= ImportXmlNamespace <alias> <target-namespace>
                    writer.WriteCompressedUInt32(WriteUTF8(((PdbImportXmlNamespace)import).Alias));
                    writer.WriteCompressedUInt32(WriteUTF8(((PdbImportXmlNamespace)import).TargetNamespace));
                    break;

                case PdbImportDefinitionKind.ImportAssemblyReferenceAlias:
                    // <import> ::= ImportReferenceAlias <alias>
                    writer.WriteCompressedUInt32(WriteUTF8(((PdbImportAssemblyReferenceAlias)import).Alias));
                    break;

                case PdbImportDefinitionKind.AliasAssemblyReference:
                    // <import> ::= AliasAssemblyReference <alias> <target-assembly>
                    writer.WriteCompressedUInt32(WriteUTF8(((PdbAliasAssemblyReference)import).Alias));
                    writer.WriteCompressedUInt32(systemMetadata.GetToken(((PdbAliasAssemblyReference)import).TargetAssembly).Rid);
                    break;

                case PdbImportDefinitionKind.AliasNamespace:
                    // <import> ::= AliasNamespace <alias> <target-namespace>
                    writer.WriteCompressedUInt32(WriteUTF8(((PdbAliasNamespace)import).Alias));
                    writer.WriteCompressedUInt32(WriteUTF8(((PdbAliasNamespace)import).TargetNamespace));
                    break;

                case PdbImportDefinitionKind.AliasAssemblyNamespace:
                    // <import> ::= AliasAssemblyNamespace <alias> <target-assembly> <target-namespace>
                    writer.WriteCompressedUInt32(WriteUTF8(((PdbAliasAssemblyNamespace)import).Alias));
                    writer.WriteCompressedUInt32(systemMetadata.GetToken(((PdbAliasAssemblyNamespace)import).TargetAssembly).Rid);
                    writer.WriteCompressedUInt32(WriteUTF8(((PdbAliasAssemblyNamespace)import).TargetNamespace));
                    break;

                case PdbImportDefinitionKind.AliasType:
                    // <import> ::= AliasType <alias> <target-type>
                    writer.WriteCompressedUInt32(WriteUTF8(((PdbAliasType)import).Alias));
                    writer.WriteCompressedUInt32(GetTypeDefOrRefEncodedToken(((PdbAliasType)import).TargetType));
                    break;

                default:
                    helper.Error2("Unknown import definition kind: {0}.", import.Kind);
                    return;
                }
            }
        }
コード例 #2
0
        public void Read(uint imports, IList <PdbImport> result)
        {
            if (imports == 0)
            {
                return;
            }
            if (!blobStream.TryCreateReader(imports, out var reader))
            {
                return;
            }
            while (reader.Position < reader.Length)
            {
                var           kind = ImportDefinitionKindUtils.ToPdbImportDefinitionKind(reader.ReadCompressedUInt32());
                string        targetNamespace, alias;
                AssemblyRef   targetAssembly;
                PdbImport     import;
                ITypeDefOrRef targetType;
                switch (kind)
                {
                case PdbImportDefinitionKind.ImportNamespace:
                    // <import> ::= ImportNamespace <target-namespace>
                    targetNamespace = ReadUTF8(reader.ReadCompressedUInt32());
                    import          = new PdbImportNamespace(targetNamespace);
                    break;

                case PdbImportDefinitionKind.ImportAssemblyNamespace:
                    // <import> ::= ImportAssemblyNamespace <target-assembly> <target-namespace>
                    targetAssembly  = TryReadAssemblyRef(reader.ReadCompressedUInt32());
                    targetNamespace = ReadUTF8(reader.ReadCompressedUInt32());
                    import          = new PdbImportAssemblyNamespace(targetAssembly, targetNamespace);
                    break;

                case PdbImportDefinitionKind.ImportType:
                    // <import> ::= ImportType <target-type>
                    targetType = TryReadType(reader.ReadCompressedUInt32());
                    import     = new PdbImportType(targetType);
                    break;

                case PdbImportDefinitionKind.ImportXmlNamespace:
                    // <import> ::= ImportXmlNamespace <alias> <target-namespace>
                    alias           = ReadUTF8(reader.ReadCompressedUInt32());
                    targetNamespace = ReadUTF8(reader.ReadCompressedUInt32());
                    import          = new PdbImportXmlNamespace(alias, targetNamespace);
                    break;

                case PdbImportDefinitionKind.ImportAssemblyReferenceAlias:
                    // <import> ::= ImportReferenceAlias <alias>
                    alias  = ReadUTF8(reader.ReadCompressedUInt32());
                    import = new PdbImportAssemblyReferenceAlias(alias);
                    break;

                case PdbImportDefinitionKind.AliasAssemblyReference:
                    // <import> ::= AliasAssemblyReference <alias> <target-assembly>
                    alias          = ReadUTF8(reader.ReadCompressedUInt32());
                    targetAssembly = TryReadAssemblyRef(reader.ReadCompressedUInt32());
                    import         = new PdbAliasAssemblyReference(alias, targetAssembly);
                    break;

                case PdbImportDefinitionKind.AliasNamespace:
                    // <import> ::= AliasNamespace <alias> <target-namespace>
                    alias           = ReadUTF8(reader.ReadCompressedUInt32());
                    targetNamespace = ReadUTF8(reader.ReadCompressedUInt32());
                    import          = new PdbAliasNamespace(alias, targetNamespace);
                    break;

                case PdbImportDefinitionKind.AliasAssemblyNamespace:
                    // <import> ::= AliasAssemblyNamespace <alias> <target-assembly> <target-namespace>
                    alias           = ReadUTF8(reader.ReadCompressedUInt32());
                    targetAssembly  = TryReadAssemblyRef(reader.ReadCompressedUInt32());
                    targetNamespace = ReadUTF8(reader.ReadCompressedUInt32());
                    import          = new PdbAliasAssemblyNamespace(alias, targetAssembly, targetNamespace);
                    break;

                case PdbImportDefinitionKind.AliasType:
                    // <import> ::= AliasType <alias> <target-type>
                    alias      = ReadUTF8(reader.ReadCompressedUInt32());
                    targetType = TryReadType(reader.ReadCompressedUInt32());
                    import     = new PdbAliasType(alias, targetType);
                    break;

                case ImportDefinitionKindUtils.UNKNOWN_IMPORT_KIND:
                    import = null;
                    break;

                default:
                    Debug.Fail("Unknown import definition kind: " + kind.ToString());
                    import = null;
                    break;
                }
                if (!(import is null))
                {
                    result.Add(import);
                }
            }
            Debug.Assert(reader.Position == reader.Length);
        }
コード例 #3
0
        void Write(BinaryWriter writer, IList <PdbImport> imports)
        {
            foreach (var import in imports)
            {
                uint rawKind;
                if (!ImportDefinitionKindUtils.ToImportDefinitionKind(import.Kind, out rawKind))
                {
                    helper.Error("Unknown import definition kind: " + import.Kind.ToString());
                    return;
                }
                writer.WriteCompressedUInt32(rawKind);
                switch (import.Kind)
                {
                case PdbImportDefinitionKind.ImportNamespace:
                    // <import> ::= ImportNamespace <target-namespace>
                    writer.WriteCompressedUInt32(WriteUTF8(((PdbImportNamespace)import).TargetNamespace));
                    break;

                case PdbImportDefinitionKind.ImportAssemblyNamespace:
                    // <import> ::= ImportAssemblyNamespace <target-assembly> <target-namespace>
                    writer.WriteCompressedUInt32(systemMetaData.GetToken(((PdbImportAssemblyNamespace)import).TargetAssembly).Rid);
                    writer.WriteCompressedUInt32(WriteUTF8(((PdbImportAssemblyNamespace)import).TargetNamespace));
                    break;

                case PdbImportDefinitionKind.ImportType:
                    // <import> ::= ImportType <target-type>
                    writer.WriteCompressedUInt32(GetTypeDefOrRefEncodedToken(((PdbImportType)import).TargetType));
                    break;

                case PdbImportDefinitionKind.ImportXmlNamespace:
                    // <import> ::= ImportXmlNamespace <alias> <target-namespace>
                    writer.WriteCompressedUInt32(WriteUTF8(((PdbImportXmlNamespace)import).Alias));
                    writer.WriteCompressedUInt32(WriteUTF8(((PdbImportXmlNamespace)import).TargetNamespace));
                    break;

                case PdbImportDefinitionKind.ImportAssemblyReferenceAlias:
                    // <import> ::= ImportReferenceAlias <alias>
                    writer.WriteCompressedUInt32(WriteUTF8(((PdbImportAssemblyReferenceAlias)import).Alias));
                    break;

                case PdbImportDefinitionKind.AliasAssemblyReference:
                    // <import> ::= AliasAssemblyReference <alias> <target-assembly>
                    writer.WriteCompressedUInt32(WriteUTF8(((PdbAliasAssemblyReference)import).Alias));
                    writer.WriteCompressedUInt32(systemMetaData.GetToken(((PdbAliasAssemblyReference)import).TargetAssembly).Rid);
                    break;

                case PdbImportDefinitionKind.AliasNamespace:
                    // <import> ::= AliasNamespace <alias> <target-namespace>
                    writer.WriteCompressedUInt32(WriteUTF8(((PdbAliasNamespace)import).Alias));
                    writer.WriteCompressedUInt32(WriteUTF8(((PdbAliasNamespace)import).TargetNamespace));
                    break;

                case PdbImportDefinitionKind.AliasAssemblyNamespace:
                    // <import> ::= AliasAssemblyNamespace <alias> <target-assembly> <target-namespace>
                    writer.WriteCompressedUInt32(WriteUTF8(((PdbAliasAssemblyNamespace)import).Alias));
                    writer.WriteCompressedUInt32(systemMetaData.GetToken(((PdbAliasAssemblyNamespace)import).TargetAssembly).Rid);
                    writer.WriteCompressedUInt32(WriteUTF8(((PdbAliasAssemblyNamespace)import).TargetNamespace));
                    break;

                case PdbImportDefinitionKind.AliasType:
                    // <import> ::= AliasType <alias> <target-type>
                    writer.WriteCompressedUInt32(WriteUTF8(((PdbAliasType)import).Alias));
                    writer.WriteCompressedUInt32(GetTypeDefOrRefEncodedToken(((PdbAliasType)import).TargetType));
                    break;

                default:
                    helper.Error("Unknown import definition kind: " + import.Kind.ToString());
                    return;
                }
            }
        }