TextPosition Struct
Represents an ordered pair of zero-based line and character index values that defines a position within the lines of an ITextSnapshot.
public readonly struct TextPosition : IComparable, IComparable<TextPosition>, IEquatable<TextPosition>
- Implements:
- IComparable IComparable<TextPosition> IEquatable<TextPosition>
Constructors
TextPosition(TextPosition, bool)
Initializes an instance of the structure with the specified TextPosition values.
public TextPosition(TextPosition position, bool hasFarAffinity = false)
| Parameter | Type | Description |
|---|---|---|
| position | TextPosition | The TextPosition specifying line and character values. |
| hasFarAffinity | bool | Whether the position has affinity for the far side, which is used when the position specifies the place
where a view line is wrapped to a second view line.
The default value is |
TextPosition(int, int, bool)
Initializes an instance of the structure with the specified line and character values.
public TextPosition(int line, int character, bool hasFarAffinity = false)
| Parameter | Type | Description |
|---|---|---|
| line | int | The line of the position. |
| character | int | The character of the position. |
| hasFarAffinity | bool | Whether the position has affinity for the far side, which is used when the position specifies the place
where a view line is wrapped to a second view line.
The default value is |
Properties
Character
The zero-based character of this TextPosition.
public int Character { get; }
Property Value
Remarks
This property is zero-based. When displaying the value in UI, use the DisplayCharacter property instead,
which adds 1 to this value to make it one-based.
DisplayCharacter
The one-based character of this TextPosition, which is better for display than use of the Character property.
DisplayLine
The one-based line of this TextPosition, which is better for display than use of the Line property.
HasFarAffinity
Indicates whether the position has affinity for the far side.
public bool HasFarAffinity { get; }
Property Value
- bool:
trueif the position has affinity for the far side; otherwise,false. The default value isfalse.
Remarks
This property is used in word wrap scenarios where the position is the last position in a view line that gets wrapped to another view line.
In that scenario, the position could refer to both the end of the first line and the beginning of the second line.
When this property is true, the position will refer to the beginning of the second line.
Line
The zero-based line of this TextPosition.
public int Line { get; }
Property Value
Remarks
This property is zero-based. When displaying the value in UI, use the DisplayCharacter property instead,
which adds 1 to this value to make it one-based.
Methods
CompareTo(TextPosition)
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(TextPosition position)
| Parameter | Type | Description |
|---|---|---|
| position | TextPosition |
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.
CompareToWithoutAffinity(TextPosition)
Compares the current instance with another TextPosition 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 TextPosition, disregarding the HasFarAffinity setting of each.
public int CompareToWithoutAffinity(TextPosition position)
| Parameter | Type | Description |
|---|---|---|
| position | TextPosition |
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.
Equals(TextPosition)
Indicates whether the current object is equal to another object of the same type.
public bool Equals(TextPosition other)
| Parameter | Type | Description |
|---|---|---|
| other | TextPosition | 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.
First(TextPosition, TextPosition)
Returns the TextPosition that comes first.
public static TextPosition First(TextPosition position1, TextPosition position2)
| Parameter | Type | Description |
|---|---|---|
| position1 | TextPosition | The first TextPosition to compare. |
| position2 | TextPosition | The second TextPosition to compare. |
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.
Last(TextPosition, TextPosition)
Returns the TextPosition that comes last.
public static TextPosition Last(TextPosition position1, TextPosition position2)
| Parameter | Type | Description |
|---|---|---|
| position1 | TextPosition | The first TextPosition to compare. |
| position2 | TextPosition | The second TextPosition to compare. |
Returns
ToString()
Returns the string representation of this object.
Operators
operator ==(TextPosition, TextPosition)
Compares two TextPosition objects. The result specifies whether the values of the Line, Character, and HasFarAffinity properties of the two TextPosition objects are equal.
public static bool operator ==(TextPosition left, TextPosition right)
| Parameter | Type | Description |
|---|---|---|
| left | TextPosition | A TextPosition to compare. |
| right | TextPosition | A TextPosition to compare. |
Returns
- bool:
trueif the Line, Character, and HasFarAffinity values ofleftandrightare equal; otherwise,false.
operator >(TextPosition, TextPosition)
Compares two TextPosition objects. The result specifies whether the values of the Line and Character properties of one TextPosition are greater than the other.
public static bool operator >(TextPosition left, TextPosition right)
| Parameter | Type | Description |
|---|---|---|
| left | TextPosition | A TextPosition to compare. |
| right | TextPosition | A TextPosition to compare. |
Returns
operator >=(TextPosition, TextPosition)
Compares two TextPosition objects. The result specifies whether the values of the Line and Character properties of one TextPosition are greater than or equal to the other.
public static bool operator >=(TextPosition left, TextPosition right)
| Parameter | Type | Description |
|---|---|---|
| left | TextPosition | A TextPosition to compare. |
| right | TextPosition | A TextPosition to compare. |
Returns
operator !=(TextPosition, TextPosition)
Compares two TextPosition objects. The result specifies whether the values of the Line, Character, and HasFarAffinity properties of the two TextPosition objects are unequal.
public static bool operator !=(TextPosition left, TextPosition right)
| Parameter | Type | Description |
|---|---|---|
| left | TextPosition | A TextPosition to compare. |
| right | TextPosition | A TextPosition to compare. |
Returns
- bool:
trueif the Line, Character, and HasFarAffinity values ofleftandrightare unequal; otherwise,false.
operator <(TextPosition, TextPosition)
Compares two TextPosition objects. The result specifies whether the values of the Line and Character properties of one TextPosition are less than the other.
public static bool operator <(TextPosition left, TextPosition right)
| Parameter | Type | Description |
|---|---|---|
| left | TextPosition | A TextPosition to compare. |
| right | TextPosition | A TextPosition to compare. |
Returns
operator <=(TextPosition, TextPosition)
Compares two TextPosition objects. The result specifies whether the values of the Line and Character properties of one TextPosition are less than or equal to the other.
public static bool operator <=(TextPosition left, TextPosition right)
| Parameter | Type | Description |
|---|---|---|
| left | TextPosition | A TextPosition to compare. |
| right | TextPosition | A TextPosition to compare. |
Returns
Fields
MaxCharacter
The maximum character value for a position.
public const int MaxCharacter = 2147483647
MaxLine
The maximum line value for a position.
public const int MaxLine = 2147483647
Zero
A TextPosition with line and character values of 0.
public static readonly TextPosition Zero