TextSnapshotRange Struct
Represents a zero-based range of two normalized offset values within a certain ITextSnapshot.
public readonly struct TextSnapshotRange : IComparable<TextRange>, IComparable<TextSnapshotRange>, IEquatable<TextSnapshotRange>, ITextPositionRangeProvider, ITextRangeProvider
- Implements:
- IComparable<TextRange> IComparable<TextSnapshotRange> IEquatable<TextSnapshotRange> ITextPositionRangeProvider ITextRangeProvider
Constructors
TextSnapshotRange(ITextSnapshot, TextRange)
Initializes an instance of the structure with the specified TextRange.
public TextSnapshotRange(ITextSnapshot snapshot, TextRange textRange)
| Parameter | Type | Description |
|---|---|---|
| snapshot | ITextSnapshot | The ITextSnapshot that contains the text range. |
| textRange | TextRange | The TextRange of the range. |
TextSnapshotRange(ITextSnapshot, int)
Initializes an instance of the structure using the specified offset for both the start and end values.
public TextSnapshotRange(ITextSnapshot snapshot, int offset)
| Parameter | Type | Description |
|---|---|---|
| snapshot | ITextSnapshot | The ITextSnapshot that contains the text range. |
| offset | int | The start and end offset in the range. |
TextSnapshotRange(ITextSnapshot, int, int)
Initializes an instance of the structure with the specified offset values.
public TextSnapshotRange(ITextSnapshot snapshot, int startOffset, int endOffset)
| Parameter | Type | Description |
|---|---|---|
| snapshot | ITextSnapshot | The ITextSnapshot that contains the text range. |
| startOffset | int | The start offset in the range. |
| endOffset | int | The end offset in the range. |
TextSnapshotRange(TextSnapshotOffset)
Initializes an instance of the structure using the specified TextSnapshotOffset for both the start and end values.
public TextSnapshotRange(TextSnapshotOffset snapshotOffset)
| Parameter | Type | Description |
|---|---|---|
| snapshotOffset | TextSnapshotOffset | The start and end offset in the range. |
Properties
AbsoluteLength
The absolute number of characters encompassed by the TextSnapshotRange.
[Obsolete("This property will be removed in a future version. Use the Length property instead, as it already returns an absolute length due to snapshot ranges always being normalized.", false)]
public int AbsoluteLength { get; }
Property Value
EndLine
The ITextSnapshotLine that contains the end offset in the text range.
EndOffset
The end offset in the range.
public int EndOffset { get; }
Property Value
Remarks
Since snapshot ranges are normalized, this property returns the last offset in the range.
EndPosition
The end TextPosition in the range.
public TextPosition EndPosition { get; }
Property Value
Remarks
Since snapshot ranges are normalized, this property returns the last TextPosition in the range.
IsZeroLength
Indicates whether the range has a zero length.
public bool IsZeroLength { get; }
Property Value
- bool:
trueif the range has a zero length; otherwise,false.
Length
The number of characters encompassed by the TextSnapshotRange.
public int Length { get; }
Property Value
Remarks
This value will always return a non-negative length since snapshot ranges are normalized.
LineTerminator
The type of line terminator that ends the snapshot range, if any.
PositionRange
A TextPositionRange that specifies the text position range of the object.
Snapshot
The ITextSnapshot that contains the text range.
StartLine
The ITextSnapshotLine that contains the start offset in the text range.
StartOffset
The start offset in the range.
public int StartOffset { get; }
Property Value
Remarks
Since snapshot ranges are normalized, this property returns the first offset in the range.
StartPosition
The start TextPosition in the range.
public TextPosition StartPosition { get; }
Property Value
Remarks
Since snapshot ranges are normalized, this property returns the first TextPosition in the range.
Text
The snapshot text substring encompassed by this range.
TextRange
A TextRange that specifies the text range of the object.
Methods
BordersOn(TextRange)
Returns whether the TextSnapshotRange borders on, but does not overlap the specified TextRange.
public bool BordersOn(TextRange range)
| Parameter | Type | Description |
|---|---|---|
| range | TextRange | The TextRange to examine. |
Returns
- bool:
trueif the TextSnapshotRange borders on, but does not overlap the specified TextRange; otherwise,false.
BordersOn(TextSnapshotRange)
Returns whether the TextSnapshotRange borders on, but does not overlap the specified TextSnapshotRange.
public bool BordersOn(TextSnapshotRange range)
| Parameter | Type | Description |
|---|---|---|
| range | TextSnapshotRange | The TextSnapshotRange to examine. |
Returns
- bool:
trueif the TextSnapshotRange borders on, but does not overlap the specified TextSnapshotRange; otherwise,false.
BordersOn(int)
Returns whether the TextSnapshotRange borders on the specified offset.
public bool BordersOn(int offset)
| Parameter | Type | Description |
|---|---|---|
| offset | int | The offset to examine. |
Returns
- bool:
trueif the TextSnapshotRange borders on the specified offset; otherwise,false.
Remarks
This method checks to see if the specified offset is either the StartOffset or EndOffset.
CompareTo(TextRange)
Compares the current instance with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other object.
public int CompareTo(TextRange range)
| Parameter | Type | Description |
|---|---|---|
| range | TextRange |
Returns
- int:
A value that indicates the relative order of the objects being compared. The return value has these meanings:
Value Meaning Less than zero This instance precedes otherin the sort order.Zero This instance occurs in the same position in the sort order as other.Greater than zero This instance follows otherin the sort order.
CompareTo(TextSnapshotRange)
Compares the current instance with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other object.
public int CompareTo(TextSnapshotRange range)
| Parameter | Type | Description |
|---|---|---|
| range | TextSnapshotRange |
Returns
- int:
A value that indicates the relative order of the objects being compared. The return value has these meanings:
Value Meaning Less than zero This instance precedes otherin the sort order.Zero This instance occurs in the same position in the sort order as other.Greater than zero This instance follows otherin the sort order.
Contains(TextRange)
Returns whether the TextSnapshotRange contains the specified TextRange.
public bool Contains(TextRange range)
| Parameter | Type | Description |
|---|---|---|
| range | TextRange | The TextRange to examine. |
Returns
- bool:
trueif the TextSnapshotRange contains the specified TextRange; otherwise,false.
Contains(TextSnapshotRange)
Returns whether the TextSnapshotRange contains the specified TextSnapshotRange.
public bool Contains(TextSnapshotRange range)
| Parameter | Type | Description |
|---|---|---|
| range | TextSnapshotRange | The TextSnapshotRange to examine. |
Returns
- bool:
trueif the TextSnapshotRange contains the specified TextSnapshotRange; otherwise,false.
Contains(int)
Returns whether the TextSnapshotRange contains the specified offset.
public bool Contains(int offset)
| Parameter | Type | Description |
|---|---|---|
| offset | int | The offset to examine. |
Returns
- bool:
trueif the TextSnapshotRange contains the specified offset; otherwise,false.
Remarks
This method returns false if the offset falls on the EndOffset offset
since this method indicates if the offset is encompassed by the TextSnapshotRange.
Equals(TextSnapshotRange)
Indicates whether the current object is equal to another object of the same type.
public bool Equals(TextSnapshotRange other)
| Parameter | Type | Description |
|---|---|---|
| other | TextSnapshotRange | An object to compare with this object. |
Returns
- bool:
trueif the current object is equal to theotherparameter; otherwise,false.
Equals(object?)
Indicates whether this instance and a specified object are equal.
public override bool Equals(object? obj)
| Parameter | Type | Description |
|---|---|---|
| obj | object | The object to compare with the current instance. |
Returns
- bool:
trueifobjand this instance are the same type and represent the same value; otherwise,false.
FromSpan(ITextSnapshot, int, int)
Returns a TextSnapshotRange that covers the specified offset and length.
public static TextSnapshotRange FromSpan(ITextSnapshot snapshot, int offset, int length)
| Parameter | Type | Description |
|---|---|---|
| snapshot | ITextSnapshot | The ITextSnapshot that contains the text range. |
| offset | int | The start offset. |
| length | int | The length of the range. |
Returns
GetHashCode()
Returns the hash code for this instance.
public override int GetHashCode()
Returns
- int:
A 32-bit signed integer that is the hash code for this instance.
GetText(LineTerminator)
Returns the snapshot text substring encompassed by this range, using the specified LineTerminator for line ends.
public string GetText(LineTerminator lineTerminator)
| Parameter | Type | Description |
|---|---|---|
| lineTerminator | LineTerminator | A LineTerminator specifying the type of line terminators to use. |
Returns
IntersectsWith(TextRange)
Returns whether the TextSnapshotRange intersects with the specified TextRange.
public bool IntersectsWith(TextRange range)
| Parameter | Type | Description |
|---|---|---|
| range | TextRange | The TextRange to examine. |
Returns
- bool:
trueif the TextSnapshotRange intersects with the specified TextRange; otherwise,false.
Remarks
This method returns whether the specified TextRange borders on or overlaps the TextSnapshotRange.
IntersectsWith(TextSnapshotRange)
Returns whether the TextSnapshotRange intersects with the specified TextSnapshotRange.
public bool IntersectsWith(TextSnapshotRange range)
| Parameter | Type | Description |
|---|---|---|
| range | TextSnapshotRange | The TextSnapshotRange to examine. |
Returns
- bool:
trueif the TextSnapshotRange intersects with the specified TextSnapshotRange; otherwise,false.
Remarks
This method returns whether the specified TextSnapshotRange borders on or overlaps the TextSnapshotRange.
IntersectsWith(TextSnapshotRange, bool, bool)
Returns whether the TextSnapshotRange intersects with the specified TextSnapshotRange.
public bool IntersectsWith(TextSnapshotRange range, bool includeFirstEdge, bool includeLastEdge)
| Parameter | Type | Description |
|---|---|---|
| range | TextSnapshotRange | The TextSnapshotRange to examine. |
| includeFirstEdge | bool | Whether to return |
| includeLastEdge | bool | Whether to return |
Returns
- bool:
trueif the TextSnapshotRange intersects with the specified TextSnapshotRange; otherwise,false.
Remarks
This method returns whether the specified TextSnapshotRange borders on or overlaps the TextSnapshotRange.
IntersectsWith(int)
Returns whether the TextSnapshotRange intersects with the specified offset.
public bool IntersectsWith(int offset)
| Parameter | Type | Description |
|---|---|---|
| offset | int | The offset to examine. |
Returns
- bool:
trueif the TextSnapshotRange intersects with the specified offset; otherwise,false.
Remarks
This method returns whether the specified offset borders on or lies within the TextSnapshotRange.
OverlapsWith(TextRange)
Returns whether the TextSnapshotRange overlaps with, or crosses, the specified TextRange.
public bool OverlapsWith(TextRange range)
| Parameter | Type | Description |
|---|---|---|
| range | TextRange | The TextRange to examine. |
Returns
- bool:
trueif the TextSnapshotRange overlaps with, or crosses, the specified TextRange; otherwise,false.
OverlapsWith(TextSnapshotRange)
Returns whether the TextSnapshotRange overlaps with, or crosses, the specified TextSnapshotRange.
public bool OverlapsWith(TextSnapshotRange range)
| Parameter | Type | Description |
|---|---|---|
| range | TextSnapshotRange | The TextSnapshotRange to examine. |
Returns
- bool:
trueif the TextSnapshotRange overlaps with, or crosses, the specified TextSnapshotRange; otherwise,false.
ToString()
Returns the string representation of this object.
ToVersionRange(TextRangeTrackingModes)
Converts this text range into an ITextVersionRange.
public ITextVersionRange ToVersionRange(TextRangeTrackingModes trackingModes)
| Parameter | Type | Description |
|---|---|---|
| trackingModes | TextRangeTrackingModes | A TextRangeTrackingModes indicating the tracking modes to use. |
Returns
ToVersionRange(Func<TextRangeTrackingModes>)
Converts this text range into an ITextVersionRange.
public ITextVersionRange ToVersionRange(Func<TextRangeTrackingModes> trackingModesFunc)
| Parameter | Type | Description |
|---|---|---|
| trackingModesFunc | Func<TextRangeTrackingModes> | A function that dynamically returns a TextRangeTrackingModes indicating the tracking modes to use. |
Returns
TranslateTo(ITextSnapshot, TextRangeTrackingModes)
Translates this text range from one ITextSnapshot to another in the same ITextDocument.
public TextSnapshotRange? TranslateTo(ITextSnapshot toSnapshot, TextRangeTrackingModes trackingModes)
| Parameter | Type | Description |
|---|---|---|
| toSnapshot | ITextSnapshot | The ITextSnapshot that is the target of the translation. |
| trackingModes | TextRangeTrackingModes | A TextRangeTrackingModes indicating the tracking modes to use. |
Returns
- TextSnapshotRange?:
The translated TextSnapshotRange, or
nullif deleted.
Operators
operator ==(TextSnapshotRange, TextSnapshotRange)
Compares two TextSnapshotRange objects. The result specifies whether the values of the StartOffset and EndOffset properties of the two TextSnapshotRange objects are equal.
public static bool operator ==(TextSnapshotRange left, TextSnapshotRange right)
| Parameter | Type | Description |
|---|---|---|
| left | TextSnapshotRange | A TextSnapshotRange to compare. |
| right | TextSnapshotRange | A TextSnapshotRange to compare. |
Returns
- bool:
trueif the StartOffset and EndOffset values ofleftandrightare equal; otherwise,false.
operator >(TextSnapshotRange, TextSnapshotRange)
Compares whether one TextSnapshotRange is greater than the other.
public static bool operator >(TextSnapshotRange left, TextSnapshotRange right)
| Parameter | Type | Description |
|---|---|---|
| left | TextSnapshotRange | A TextSnapshotRange to compare. |
| right | TextSnapshotRange | A TextSnapshotRange to compare. |
Returns
- bool:
trueif the TextSnapshotRange inleftis greater than the TextSnapshotRange inright; otherwise,false.
operator >=(TextSnapshotRange, TextSnapshotRange)
Compares whether one TextSnapshotRange is greater than or equal to the other.
public static bool operator >=(TextSnapshotRange left, TextSnapshotRange right)
| Parameter | Type | Description |
|---|---|---|
| left | TextSnapshotRange | A TextSnapshotRange to compare. |
| right | TextSnapshotRange | A TextSnapshotRange to compare. |
Returns
- bool:
trueif the TextSnapshotRange inleftis greater than or equal to the TextSnapshotRange inright; otherwise,false.
implicit operator TextRange(TextSnapshotRange)
Implicitly converts a TextSnapshotRange instance to a TextRange.
public static implicit operator TextRange(TextSnapshotRange range)
| Parameter | Type | Description |
|---|---|---|
| range | TextSnapshotRange | The TextSnapshotRange to convert. |
Returns
operator !=(TextSnapshotRange, TextSnapshotRange)
Compares two TextSnapshotRange objects. The result specifies whether the values of the StartOffset and EndOffset properties of the two TextSnapshotRange objects are unequal.
public static bool operator !=(TextSnapshotRange left, TextSnapshotRange right)
| Parameter | Type | Description |
|---|---|---|
| left | TextSnapshotRange | A TextSnapshotRange to compare. |
| right | TextSnapshotRange | A TextSnapshotRange to compare. |
Returns
- bool:
trueif the StartOffset and EndOffset values ofleftandrightare unequal; otherwise,false.
operator <(TextSnapshotRange, TextSnapshotRange)
Compares whether one TextSnapshotRange is less than the other.
public static bool operator <(TextSnapshotRange left, TextSnapshotRange right)
| Parameter | Type | Description |
|---|---|---|
| left | TextSnapshotRange | A TextSnapshotRange to compare. |
| right | TextSnapshotRange | A TextSnapshotRange to compare. |
Returns
- bool:
trueif the TextSnapshotRange inleftis less than the TextSnapshotRange inright; otherwise,false.
operator <=(TextSnapshotRange, TextSnapshotRange)
Compares whether one TextSnapshotRange is less than or equal to the other.
public static bool operator <=(TextSnapshotRange left, TextSnapshotRange right)
| Parameter | Type | Description |
|---|---|---|
| left | TextSnapshotRange | A TextSnapshotRange to compare. |
| right | TextSnapshotRange | A TextSnapshotRange to compare. |
Returns
- bool:
trueif the TextSnapshotRange inleftis less than or equal to the TextSnapshotRange inright; otherwise,false.