TextPositionRange Struct
Represents a range of two TextPosition values within the lines of an ITextSnapshot, inclusive of the start TextPosition and exclusive of the end TextPosition.
public readonly struct TextPositionRange : IEquatable<TextPositionRange>
- Implements:
- IEquatable<TextPositionRange>
Constructors
TextPositionRange(TextPosition)
Initializes an instance of the structure with the specified TextPosition value for both start and end.
public TextPositionRange(TextPosition position)
| Parameter | Type | Description |
|---|---|---|
| position | TextPosition | The TextPosition to use as the start and end of the range. |
TextPositionRange(TextPosition, TextPosition)
Represents a range of two TextPosition values within the lines of an ITextSnapshot, inclusive of the start TextPosition and exclusive of the end TextPosition.
public TextPositionRange(TextPosition startPosition, TextPosition endPosition)
| Parameter | Type | Description |
|---|---|---|
| startPosition | TextPosition | The start TextPosition in the range. |
| endPosition | TextPosition | The end TextPositionin the range. |
TextPositionRange(int, int, int, int)
Initializes an instance of the structure with the specified TextPosition values.
public TextPositionRange(int startLine, int startCharacter, int endLine, int endCharacter)
| Parameter | Type | Description |
|---|---|---|
| startLine | int | The line of the start TextPositionin the range. |
| startCharacter | int | The character of the start TextPositionin the range. |
| endLine | int | The line of the end TextPositionin the range. |
| endCharacter | int | The character of the end TextPositionin the range. |
Properties
EndPosition
The end TextPosition in the range.
public TextPosition EndPosition { get; }
Property Value
Remarks
The end TextPosition may occur before the start TextPosition if the range is not normalized. The IsNormalized property indicates if the range is normalized. To get the normalized first TextPosition in the range, use the FirstPosition property. To get the normalized last TextPosition in the range, use the LastPosition property.
FirstPosition
The first TextPosition in the range.
public TextPosition FirstPosition { get; }
Property Value
Remarks
This property returns either the StartPosition or EndPosition property, whichever comes first.
IsNormalized
Indicates whether the range is normalized (StartPosition occurs at or before the EndPosition).
public bool IsNormalized { get; }
Property Value
- bool:
trueif the range is normalized; otherwise,false.
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.
LastPosition
The last TextPosition in the range.
public TextPosition LastPosition { get; }
Property Value
Remarks
This property returns either the StartPosition or EndPosition property, whichever comes last.
Lines
The number of lines encompassed by the TextPositionRange.
Normalized
A TextPositionRange that ensures the StartPosition occurs at or before the EndPositionTextPosition.
StartPosition
The start TextPosition in the range.
public TextPosition StartPosition { get; }
Property Value
Remarks
The start TextPosition may occur after the end TextPosition if the range is not normalized. The IsNormalized property indicates if the range is normalized. To get the normalized first TextPosition in the range, use the FirstPosition property. To get the normalized last TextPosition in the range, use the LastPosition property.
Methods
BordersOn(TextPosition)
Returns whether the TextPositionRange borders on the specified TextPosition.
public bool BordersOn(TextPosition position)
| Parameter | Type | Description |
|---|---|---|
| position | TextPosition | The TextPosition to examine. |
Returns
- bool:
trueif the TextPositionRange borders on the specified TextPosition; otherwise,false.
Remarks
This method checks to see if the specified TextPosition is either the StartPosition or EndPosition.
BordersOn(TextPositionRange)
Returns whether the TextPositionRange borders on, but does not overlap the specified TextPositionRange.
public bool BordersOn(TextPositionRange range)
| Parameter | Type | Description |
|---|---|---|
| range | TextPositionRange | The TextPositionRange to examine. |
Returns
- bool:
trueif the TextPositionRange borders on, but does not overlap the specified TextPositionRange; otherwise,false.
Contains(TextPosition)
Returns whether the TextPositionRange contains the specified TextPosition.
public bool Contains(TextPosition position)
| Parameter | Type | Description |
|---|---|---|
| position | TextPosition | The TextPosition to examine. |
Returns
- bool:
trueif the TextPositionRange contains the specified TextPosition; otherwise,false.
Remarks
This method returns false if the TextPosition falls on the LastPositionTextPosition
since this method indicates if the TextPosition is encompassed by the TextPositionRange.
Contains(TextPositionRange)
Returns whether the TextPositionRange contains the specified TextPositionRange.
public bool Contains(TextPositionRange range)
| Parameter | Type | Description |
|---|---|---|
| range | TextPositionRange | The TextPositionRange to examine. |
Returns
- bool:
trueif the TextPositionRange contains the specified TextPositionRange; otherwise,false.
CreateCollection(TextPositionRange, bool)
Creates a collection containing a single TextPositionRange object.
public static ITextPositionRangeCollection CreateCollection(TextPositionRange positionRange, bool isBlock)
| Parameter | Type | Description |
|---|---|---|
| positionRange | TextPositionRange | The single position range. |
| isBlock | bool | Whether the position range is a special rectangular block. |
Returns
CreateCollection(IEnumerable<TextPositionRange>, int)
Creates a collection of TextPositionRange objects.
public static ITextPositionRangeCollection CreateCollection(IEnumerable<TextPositionRange> positionRanges, int primaryIndex)
| Parameter | Type | Description |
|---|---|---|
| positionRanges | IEnumerable<TextPositionRange> | The non-overlapping position ranges, in sorted order. |
| primaryIndex | int | The primary range index. |
Returns
Equals(TextPositionRange)
Indicates whether the current object is equal to another object of the same type.
public bool Equals(TextPositionRange other)
| Parameter | Type | Description |
|---|---|---|
| other | TextPositionRange | 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.
GetHashCode()
Returns a hash code for this object.
public override int GetHashCode()
Returns
- int:
An integer value that specifies a hash value for this object.
IntersectsWith(TextPosition)
Returns whether the TextPositionRange intersects with the specified TextPosition.
public bool IntersectsWith(TextPosition position)
| Parameter | Type | Description |
|---|---|---|
| position | TextPosition | The TextPosition to examine. |
Returns
- bool:
trueif the TextPositionRange intersects with the specified TextPosition; otherwise,false.
IntersectsWith(TextPositionRange)
Returns whether the TextPositionRange intersects with the specified TextPositionRange.
public bool IntersectsWith(TextPositionRange range)
| Parameter | Type | Description |
|---|---|---|
| range | TextPositionRange | The TextPositionRange to examine. |
Returns
- bool:
trueif the TextPositionRange intersects with the specified TextPositionRange; otherwise,false.
OverlapsWith(TextPositionRange)
Returns whether the TextPositionRange overlaps with, or crosses, the specified TextPositionRange.
public bool OverlapsWith(TextPositionRange range)
| Parameter | Type | Description |
|---|---|---|
| range | TextPositionRange | The TextPositionRange to examine. |
Returns
- bool:
trueif the TextPositionRange overlaps with, or crosses, the specified TextPositionRange; otherwise,false.
ToString()
Returns the string representation of this object.
Union(TextPositionRange, TextPositionRange)
Returns the normalized union of two TextPositionRange objects.
public static TextPositionRange Union(TextPositionRange range1, TextPositionRange range2)
| Parameter | Type | Description |
|---|---|---|
| range1 | TextPositionRange | The first TextPositionRange to examine. |
| range2 | TextPositionRange | The second TextPositionRange to examine. |
Returns
Operators
operator ==(TextPositionRange, TextPositionRange)
Compares two TextPositionRange objects. The result specifies whether the values of the StartPosition and EndPosition properties of the two TextPositionRange objects are equal.
public static bool operator ==(TextPositionRange left, TextPositionRange right)
| Parameter | Type | Description |
|---|---|---|
| left | TextPositionRange | A TextPositionRange to compare. |
| right | TextPositionRange | A TextPositionRange to compare. |
Returns
- bool:
trueif the StartPosition and EndPosition values ofleftandrightare equal; otherwise,false.
operator !=(TextPositionRange, TextPositionRange)
Compares two TextPositionRange objects. The result specifies whether the values of the StartPosition and EndPosition properties of the two TextPositionRange objects are unequal.
public static bool operator !=(TextPositionRange left, TextPositionRange right)
| Parameter | Type | Description |
|---|---|---|
| left | TextPositionRange | A TextPositionRange to compare. |
| right | TextPositionRange | A TextPositionRange to compare. |
Returns
- bool:
trueif the StartPosition and EndPosition values ofleftandrightare unequal; otherwise,false.