TextRange Struct

Definition

An immutable text range in a particular ITextDocumentSnapshot version.

public readonly struct TextRange : System.Collections.Generic.IEnumerable<char>, System.Collections.Generic.IReadOnlyCollection<char>, System.Collections.Generic.IReadOnlyList<char>
type TextRange = struct
    interface IReadOnlyList<char>
    interface seq<char>
    interface IEnumerable
    interface IReadOnlyCollection<char>
Public Structure TextRange
Implements IEnumerable(Of Char), IReadOnlyCollection(Of Char), IReadOnlyList(Of Char)
Inheritance
TextRange
Implements

Remarks

Microsoft.VisualStudio.RpcContracts.Utilities.VersionedTextDocumentRangeContract is one of three closely related concepts: - TextRange: Thick object representing a range of text in a ITextDocumentSnapshot. This type should be used in all code within the same process.

- Microsoft.VisualStudio.RpcContracts.Utilities.VersionedTextDocumentRangeContract: A serializable representation of TextRange that can be sent between processes over RPC. This type should be used in most RPC contracts between processes.

- Range: A serializable representation of TextRange that can be sent between processes over RPC. As opposed to Microsoft.VisualStudio.RpcContracts.Utilities.VersionedTextDocumentRangeContract, it omits the Uri and document version, making for a smaller serializable representation. This type should be used in RPC contracts that contain lots of range equivalents that need to reduce their payload size for performance. These RPC contracts will need to pass the document Uri and version for the range to be rehydrated into TextRange by IEditorHostService.

Constructors

TextRange(ITextDocumentSnapshot, Int32, Int32)

Initializes a new instance of a TextRange with the specified document, start point, and length.

TextRange(TextPosition, Int32)

Initializes a new instance of a TextRange from an existing TextPosition and a specified length.

TextRange(TextPosition, TextPosition)

Initializes a new instance of a TextRange from two TextPosition objects.

Properties

Document

The ITextDocumentSnapshot to which this snapshot range refers.

End

Gets the end of the snapshot range. The range is open-ended on the right side, which is to say that Start + Length = End.

IsEmpty

Determines whether or not this range is empty.

Item[Int32]

Gets a single character at the specified position.

Length

Gets the length of the range, which is always non-negative.

RpcContract

Converts this thick object into a serializable representation for use in an RPC call.

Start

Gets the starting index of the snapshot range.

Methods

Contains(Int32)

Determines whether the position lies within the range.

Contains(TextPosition)

Determines whether a given TextPosition lies within the range.

Contains(TextRange)

Determines whether range falls completely within this range.

CopyTo(Span<Char>)

Copy this text to the specified Span<T>.

Equals(Object)

Determines whether two snapshot ranges are the same.

Equals(String, Boolean)

Determines whether the text of this range is equivalent to a string.

GetHashCode()

Serves as a hash function for this type.

Intersection(TextRange)

Computes the intersection with the given TextRange, or null if there is no intersection.

IntersectsWith(TextRange)

Determines whether range intersects this range. Two ranges are considered to intersect if they have positions in common, or the end of one range coincides with the start of the other range, and neither is empty.

Overlap(TextRange)

Returns the overlap with the given TextRange, or null if there is no overlap.

OverlapsWith(TextRange)

Determines whether range overlaps this range. Two ranges are considered to overlap if they have positions in common and are not empty. Empty ranges do not overlap with any other range.

Slice(Int32, Int32)

Create a slice of the current TextRange.

TranslateTo(ITextDocumentSnapshot, TextRangeTrackingMode)

Translates this TextRange to an older or newer ITextDocumentSnapshot version.

Operators

Equality(TextRange, TextRange)

Determines whether two snapshot ranges are the same.

Implicit(TextRange to VersionedTextDocumentRangeContract)

Implicitly converts the TextRange to Microsoft.VisualStudio.RpcContracts.Utilities.VersionedTextDocumentRangeContract.

Inequality(TextRange, TextRange)

Determines whether two snapshot ranges are different.

Explicit Interface Implementations

IEnumerable.GetEnumerator()
IEnumerable<Char>.GetEnumerator()
IReadOnlyCollection<Char>.Count

Extension Methods

CopyToString(TextRange)

Copies the TextRange to a string.

EndsWith(TextRange, String, Boolean)

Determines whether this range ends with the given text.

IndexOf(TextRange, String, Boolean)

Determines the position of the given text in the range. Returns -1 if the text can't be found.

LastIndexOf(TextRange, String, Boolean)

Determines the last position of the given text in the range. Returns -1 if the text can't be found.

StartsWith(TextRange, String, Boolean)

Determines whether this range starts with the given text.

Applies to