In This Article

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 false.

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 false.

Properties

Character

The zero-based character of this TextPosition.

public int Character { get; }

Property Value

int

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.

public int DisplayCharacter { get; }

Property Value

int

DisplayLine

The one-based line of this TextPosition, which is better for display than use of the Line property.

public int DisplayLine { get; }

Property Value

int

HasFarAffinity

Indicates whether the position has affinity for the far side.

public bool HasFarAffinity { get; }

Property Value

bool:

true if the position has affinity for the far side; otherwise, false. The default value is false.

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

int

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 other in the sort order.
Zero This instance occurs in the same position in the sort order as other.
Greater than zero This instance follows other in 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 other in the sort order.
Zero This instance occurs in the same position in the sort order as other.
Greater than zero This instance follows other in 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:

true if the current object is equal to the other parameter; 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:

true if obj and 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

TextPosition

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

TextPosition

ToString()

Returns the string representation of this object.

public override string ToString()

Returns

string:

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:

true if the Line, Character, and HasFarAffinity values of left and right are 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

bool:

true if the Line and Character values of left and right are greater than the other; 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 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

bool:

true if the Line and Character values of left and right are greater than or equal to the other; otherwise, false.

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:

true if the Line, Character, and HasFarAffinity values of left and right are 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

bool:

true if the Line and Character values of left and right are less than the other; 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 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

bool:

true if the Line and Character values of left and right are less than or equal to the other; otherwise, false.

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

Inherited Members