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 struct TextPosition : ICloneable, IComparable
Implements:
ICloneable IComparable

Constructors

TextPosition(TextPosition, bool)

Initializes a new instance of the TextPosition class 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 a new instance of the TextPosition class 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

Gets the zero-based character of this TextPosition.

public int Character { get; }

Property Value

int:

The zero-based character of this TextPosition.

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

Gets 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:

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

DisplayLine

Gets 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:

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

HasFarAffinity

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

IsEmpty

Returns whether the TextPosition is empty.

public bool IsEmpty { get; }

Property Value

bool:

true if the TextPosition is empty; otherwise, false.

Line

Gets the zero-based line of this TextPosition.

public int Line { get; }

Property Value

int:

The zero-based line of this TextPosition.

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

Clone()

Creates a copy of this TextPosition object.

public object Clone()

Returns

object:

The TextPosition object that this method creates.

CompareTo(TextPosition)

Compares the current instance with another TextPosition.

public int CompareTo(TextPosition position)
Parameter Type Description
position TextPosition

A TextPosition to compare with this instance.

Returns

int:

A 32-bit signed integer that indicates the relative order of the comparands.

CompareTo(object)

Compares the current instance with another object of the same type.

public int CompareTo(object obj)
Parameter Type Description
obj object

An object to compare with this instance.

Returns

int:

A 32-bit signed integer that indicates the relative order of the comparands.

Equals(object)

Determines whether the specified Object is equal to the current Object.

public override bool Equals(object obj)
Parameter Type Description
obj object

The Object to compare to the current Object.

Returns

bool:

true if the specified Object is equal to the current Object; 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:

The TextPosition that comes first.

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.

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:

The TextPosition that comes last.

ToString()

Converts the object to a String.

public override string ToString()

Returns

string:

A string whose value represents this object.

Operators

operator ==(TextPosition, TextPosition)

Compares two TextPosition objects. The result specifies whether the values of the Line and Character 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 and Character 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 and Character 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 and Character 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

Empty

Returns an empty TextPosition.

public static readonly TextPosition Empty

MaxCharacter

Gets the maximum character value for a position.

public const int MaxCharacter = 2147483647

MaxLine

Gets the maximum line value for a position.

public const int MaxLine = 2147483647

Zero

Returns a TextPosition with line and character values of 0.

public static readonly TextPosition Zero

Inherited Members