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);
        }
        private int GetOrAddDocument(DebugSourceDocument document, Dictionary <DebugSourceDocument, int> index)
        {
            int documentRowId;

            if (!index.TryGetValue(document, out documentRowId))
            {
                documentRowId = _documentTable.Count + 1;
                index.Add(document, documentRowId);

                var 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);
        }