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, Boolean)

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 Boolean

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(Int32, Int32, Boolean)

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 Int32

The line of the position.

character Int32

The character of the position.

hasFarAffinity Boolean

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

Int32:

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

Int32:

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

Int32:

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

Boolean:

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

Boolean:

true if the TextPosition is empty; otherwise, false.

Line

Gets the zero-based line of this TextPosition.

public int Line { get; }

Property Value

Int32:

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

Int32:

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

Int32:

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

Boolean:

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

Int32:

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

Equality(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

Boolean:

true if the Line and Character values of left and right are equal; otherwise, false.

GreaterThan(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

Boolean:

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

GreaterThanOrEqual(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

Boolean:

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

Inequality(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

Boolean:

true if the Line and Character values of left and right are unequal; otherwise, false.

LessThan(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

Boolean:

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

LessThanOrEqual(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

Boolean:

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