ITextSnapshot oldSnapshot = textView.TextSnapshot; ITextSnapshot newSnapshot = args.Snapshot; SnapshotSpan span = new SnapshotSpan(oldSnapshot.GetLineFromLineNumber(5).Start, newSnapshot.Length - 1); SnapshotSpan translatedSpan = span.TranslateTo(newSnapshot, SpanTrackingMode.EdgeExclusive);
ITextSnapshot oldSnapshot = buffer.CurrentSnapshot; ITextSnapshotLine startLine = oldSnapshot.GetLineFromPosition(insertionPosition); ITextSnapshotLine endLine = oldSnapshot.GetLineFromLineNumber(startLine.LineNumber + 1); SnapshotSpan span = new SnapshotSpan(startLine.Start, endLine.End); ITextSnapshot newSnapshot = newSnapshotLine.Snapshot; SnapshotSpan translatedSpan = span.TranslateTo(newSnapshot, SpanTrackingMode.EdgeInclusive);In this example, we define an `ITextSnapshot` object `oldSnapshot`, and use it to get the start and end lines of the span we want to translate using the `GetLineFromPosition` and `GetLineFromLineNumber` methods. We then create a `SnapshotSpan` object `span` based on these start and end positions. We create a new snapshot `newSnapshot` and use the `TranslateTo` method to translate `span` to this new snapshot using `SpanTrackingMode.EdgeInclusive`. The resulting translated span is stored in the `translatedSpan` variable. Package/Library: Microsoft.VisualStudio.Text.dll.