private DocumentHandle AddDocument(DebugSourceDocument document, Dictionary <DebugSourceDocument, DocumentHandle> index)
        {
            DocumentHandle  documentHandle;
            DebugSourceInfo info = document.GetSourceInfo();

            var name = document.Location;

            if (_usingNonSourceDocumentNameEnumerator)
            {
                var result = _nonSourceDocumentNameEnumerator.MoveNext();
                Debug.Assert(result);
                name = _nonSourceDocumentNameEnumerator.Current;
            }

            documentHandle = _debugMetadataOpt.AddDocument(
                name: _debugMetadataOpt.GetOrAddDocumentName(name),
                hashAlgorithm: info.Checksum.IsDefault ? default(GuidHandle) : _debugMetadataOpt.GetOrAddGuid(info.ChecksumAlgorithmId),
                hash: info.Checksum.IsDefault ? default(BlobHandle) : _debugMetadataOpt.GetOrAddBlob(info.Checksum),
                language: _debugMetadataOpt.GetOrAddGuid(document.Language));

            index.Add(document, documentHandle);

            if (info.EmbeddedTextBlob != null)
            {
                _debugMetadataOpt.AddCustomDebugInformation(
                    parent: documentHandle,
                    kind: _debugMetadataOpt.GetOrAddGuid(PortableCustomDebugInfoKinds.EmbeddedSource),
                    value: _debugMetadataOpt.GetOrAddBlob(info.EmbeddedTextBlob));
            }

            return(documentHandle);
        }
        private DocumentHandle GetOrAddDocument(DebugSourceDocument document, Dictionary <DebugSourceDocument, DocumentHandle> index)
        {
            DocumentHandle documentHandle;

            if (!index.TryGetValue(document, out documentHandle))
            {
                DebugSourceInfo info = document.GetSourceInfo();

                documentHandle = _debugMetadataOpt.AddDocument(
                    name: _debugMetadataOpt.GetOrAddDocumentName(document.Location),
                    hashAlgorithm: info.Checksum.IsDefault ? default(GuidHandle) : _debugMetadataOpt.GetOrAddGuid(info.ChecksumAlgorithmId),
                    hash: info.Checksum.IsDefault ? default(BlobHandle) : _debugMetadataOpt.GetOrAddBlob(info.Checksum),
                    language: _debugMetadataOpt.GetOrAddGuid(document.Language));

                index.Add(document, documentHandle);

                if (info.EmbeddedTextBlob != null)
                {
                    _debugMetadataOpt.AddCustomDebugInformation(
                        parent: documentHandle,
                        kind: _debugMetadataOpt.GetOrAddGuid(PortableCustomDebugInfoKinds.EmbeddedSource),
                        value: _debugMetadataOpt.GetOrAddBlob(info.EmbeddedTextBlob));
                }
            }

            return(documentHandle);
        }
예제 #3
0
        private int GetOrAddDocument(DebugSourceDocument document, Dictionary <DebugSourceDocument, int> index)
        {
            if (!index.TryGetValue(document, out int documentRowId))
            {
                documentRowId = _documentTable.Count + 1;
                index.Add(document, documentRowId);

                DebugSourceInfo sourceInfo = document.GetSourceInfo();
                _documentTable.Add(new DocumentRow
                {
                    Name          = SerializeDocumentName(document.Location),
                    HashAlgorithm = (sourceInfo.Checksum.IsDefault ? default(GuidHandle) : GetOrAddGuid(sourceInfo.ChecksumAlgorithmId)),
                    Hash          = (sourceInfo.Checksum.IsDefault) ? default(BlobHandle) : GetOrAddBlob(sourceInfo.Checksum)
                });
            }

            return(documentRowId);
        }