/// <summary> /// Translates this snapshot span to a different snapshot of the same <see cref="ITextBuffer"/>. /// </summary> /// <param name="targetSnapshot">The snapshot to which to translate.</param> /// <param name="spanTrackingMode">The <see cref="SpanTrackingMode"/> to use in the translation.</param> /// <returns>A new snapshot span.</returns> /// <exception cref="ArgumentNullException"><paramref name="targetSnapshot"/> is null.</exception> /// <exception cref="ArgumentException"><paramref name="targetSnapshot"/> does not refer to the same <see cref="ITextBuffer"/> as this snapshot span.</exception> public SnapshotSpan TranslateTo(ITextSnapshot targetSnapshot, SpanTrackingMode spanTrackingMode) { if (targetSnapshot == this.Snapshot) { return(this); } else { if (targetSnapshot == null) { throw new ArgumentNullException("targetSnapshot"); } if (targetSnapshot.TextBuffer != this.Start.Snapshot.TextBuffer) { throw new ArgumentException(Strings.InvalidSnapshot); } Span targetSpan = targetSnapshot.Version.VersionNumber > this.Snapshot.Version.VersionNumber ? Tracking.TrackSpanForwardInTime(spanTrackingMode, Span, this.Snapshot.Version, targetSnapshot.Version) : Tracking.TrackSpanBackwardInTime(spanTrackingMode, Span, this.Snapshot.Version, targetSnapshot.Version); return(new SnapshotSpan(targetSnapshot, targetSpan)); } }
/// <summary> /// Translates this snapshot Point to a different snapshot of the same <see cref="ITextBuffer"/>. /// </summary> /// <param name="targetSnapshot">The snapshot to which to translate.</param> /// <param name="trackingMode">The <see cref="PointTrackingMode"/> to use in the translation.</param> /// <returns>A new snapshot point that has been mapped to the requested snapshot.</returns> /// <exception cref="ArgumentNullException"><paramref name="targetSnapshot"/> is null.</exception> /// <exception cref="ArgumentException"><paramref name="targetSnapshot"/> does not refer to the same <see cref="ITextBuffer"/> as this snapshot point.</exception> public SnapshotPoint TranslateTo(ITextSnapshot targetSnapshot, PointTrackingMode trackingMode) { if (targetSnapshot == this.Snapshot) { return(this); } else { if (targetSnapshot == null) { throw new ArgumentNullException(nameof(targetSnapshot)); } if (targetSnapshot.TextBuffer != this.Snapshot.TextBuffer) { throw new ArgumentException(Strings.InvalidSnapshot); } int targetPosition = targetSnapshot.Version.VersionNumber > this.Snapshot.Version.VersionNumber ? Tracking.TrackPositionForwardInTime(trackingMode, this.Position, this.Snapshot.Version, targetSnapshot.Version) : Tracking.TrackPositionBackwardInTime(trackingMode, this.Position, this.Snapshot.Version, targetSnapshot.Version); return(new SnapshotPoint(targetSnapshot, targetPosition)); } }