コード例 #1
0
        private unsafe void SetFileUpdates(
            Interop.IDebugUpdateInMemoryPE2 updater,
            List<KeyValuePair<DocumentId, ImmutableArray<LineChange>>> edits)
        {
            int totalEditCount = edits.Sum(e => e.Value.Length);
            if (totalEditCount == 0)
            {
                return;
            }

            var lineUpdates = new Interop.LINEUPDATE[totalEditCount];
            fixed (Interop.LINEUPDATE* lineUpdatesPtr = lineUpdates)
            {
                int index = 0;
                var fileUpdates = new Interop.FILEUPDATE[edits.Count];
                for (int f = 0; f < fileUpdates.Length; f++)
                {
                    var documentId = edits[f].Key;
                    var deltas = edits[f].Value;

                    fileUpdates[f].FileName = _vsProject.GetDocumentOrAdditionalDocument(documentId).FilePath;
                    fileUpdates[f].LineUpdateCount = (uint)deltas.Length;
                    fileUpdates[f].LineUpdates = (IntPtr)(lineUpdatesPtr + index);

                    for (int l = 0; l < deltas.Length; l++)
                    {
                        lineUpdates[index + l].Line = (uint)deltas[l].OldLine;
                        lineUpdates[index + l].UpdatedLine = (uint)deltas[l].NewLine;
                    }

                    index += deltas.Length;
                }

                // The updater makes a copy of all data, we can release the buffer after the call.
                updater.SetFileUpdates(fileUpdates, (uint)fileUpdates.Length);
            }
        }