/// <inheritdoc/>
        protected override void InitializeInternal(DataReaderFactory mdReaderFactory, uint metadataBaseOffset)
        {
            DotNetStream dns = null;

            try {
                foreach (var sh in mdHeader.StreamHeaders)
                {
                    switch (sh.Name.ToUpperInvariant())
                    {
                    case "#STRINGS":
                        if (stringsStream == null)
                        {
                            stringsStream = new StringsStream(mdReaderFactory, metadataBaseOffset, sh);
                            allStreams.Add(stringsStream);
                            continue;
                        }
                        break;

                    case "#US":
                        if (usStream == null)
                        {
                            usStream = new USStream(mdReaderFactory, metadataBaseOffset, sh);
                            allStreams.Add(usStream);
                            continue;
                        }
                        break;

                    case "#BLOB":
                        if (blobStream == null)
                        {
                            blobStream = new BlobStream(mdReaderFactory, metadataBaseOffset, sh);
                            allStreams.Add(blobStream);
                            continue;
                        }
                        break;

                    case "#GUID":
                        if (guidStream == null)
                        {
                            guidStream = new GuidStream(mdReaderFactory, metadataBaseOffset, sh);
                            allStreams.Add(guidStream);
                            continue;
                        }
                        break;

                    case "#~":                          // Only if #Schema is used
                    case "#-":
                        if (tablesStream == null)
                        {
                            tablesStream = new TablesStream(mdReaderFactory, metadataBaseOffset, sh);
                            allStreams.Add(tablesStream);
                            continue;
                        }
                        break;

                    case "#PDB":
                        // Case sensitive comparison since it's a stream that's not read by the CLR,
                        // only by other libraries eg. System.Reflection.Metadata.
                        if (isStandalonePortablePdb && pdbStream == null && sh.Name == "#Pdb")
                        {
                            pdbStream = new PdbStream(mdReaderFactory, metadataBaseOffset, sh);
                            allStreams.Add(pdbStream);
                            continue;
                        }
                        break;
                    }
                    dns = new CustomDotNetStream(mdReaderFactory, metadataBaseOffset, sh);
                    allStreams.Add(dns);
                    dns = null;
                }
            }
            finally {
                dns?.Dispose();
            }

            if (tablesStream == null)
            {
                throw new BadImageFormatException("Missing MD stream");
            }

            if (pdbStream != null)
            {
                tablesStream.Initialize(pdbStream.TypeSystemTableRows);
            }
            else
            {
                tablesStream.Initialize(null);
            }

            // The pointer tables are used iff row count != 0
            hasFieldPtr    = !tablesStream.FieldPtrTable.IsEmpty;
            hasMethodPtr   = !tablesStream.MethodPtrTable.IsEmpty;
            hasParamPtr    = !tablesStream.ParamPtrTable.IsEmpty;
            hasEventPtr    = !tablesStream.EventPtrTable.IsEmpty;
            hasPropertyPtr = !tablesStream.PropertyPtrTable.IsEmpty;
            hasDeletedRows = tablesStream.HasDelete;
        }
        /// <inheritdoc/>
        protected override void InitializeInternal(DataReaderFactory mdReaderFactory, uint metadataBaseOffset)
        {
            DotNetStream dns           = null;
            var          newAllStreams = new List <DotNetStream>(allStreams);

            try {
                for (int i = mdHeader.StreamHeaders.Count - 1; i >= 0; i--)
                {
                    var sh = mdHeader.StreamHeaders[i];
                    switch (sh.Name)
                    {
                    case "#Strings":
                        if (stringsStream == null)
                        {
                            stringsStream = new StringsStream(mdReaderFactory, metadataBaseOffset, sh);
                            newAllStreams.Add(stringsStream);
                            continue;
                        }
                        break;

                    case "#US":
                        if (usStream == null)
                        {
                            usStream = new USStream(mdReaderFactory, metadataBaseOffset, sh);
                            newAllStreams.Add(usStream);
                            continue;
                        }
                        break;

                    case "#Blob":
                        if (blobStream == null)
                        {
                            blobStream = new BlobStream(mdReaderFactory, metadataBaseOffset, sh);
                            newAllStreams.Add(blobStream);
                            continue;
                        }
                        break;

                    case "#GUID":
                        if (guidStream == null)
                        {
                            guidStream = new GuidStream(mdReaderFactory, metadataBaseOffset, sh);
                            newAllStreams.Add(guidStream);
                            continue;
                        }
                        break;

                    case "#~":
                        if (tablesStream == null)
                        {
                            tablesStream = new TablesStream(mdReaderFactory, metadataBaseOffset, sh);
                            newAllStreams.Add(tablesStream);
                            continue;
                        }
                        break;

                    case "#Pdb":
                        if (isStandalonePortablePdb && pdbStream == null)
                        {
                            pdbStream = new PdbStream(mdReaderFactory, metadataBaseOffset, sh);
                            allStreams.Add(pdbStream);
                            continue;
                        }
                        break;
                    }
                    dns = new CustomDotNetStream(mdReaderFactory, metadataBaseOffset, sh);
                    newAllStreams.Add(dns);
                    dns = null;
                }
            }
            finally {
                dns?.Dispose();
                newAllStreams.Reverse();
                allStreams = newAllStreams;
            }

            if (tablesStream == null)
            {
                throw new BadImageFormatException("Missing MD stream");
            }

            if (pdbStream != null)
            {
                tablesStream.Initialize(pdbStream.TypeSystemTableRows);
            }
            else
            {
                tablesStream.Initialize(null);
            }
        }