In This Article

TextPositionRange Struct

Represents a range of two TextPosition values within the lines of an ITextSnapshot.

public struct TextPositionRange : ICloneable
Implements:
ICloneable

Constructors

TextPositionRange(TextPosition)

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

Initializes a new instance of the TextPositionRange class with the specified TextPosition values.

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

Empty

Returns an empty TextPositionRange.

public static TextPositionRange Empty { get; }

Property Value

TextPositionRange:

A TextPositionRange that is empty.

EndPosition

Gets the end TextPosition in the range.

public TextPosition EndPosition { get; }

Property Value

TextPosition:

The end TextPosition in the range.

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

Gets the first TextPosition in the range.

public TextPosition FirstPosition { get; }

Property Value

TextPosition:

The first TextPosition in the range.

Remarks

This property returns either the StartPosition or EndPosition property, whichever comes first.

IsEmpty

Returns whether the TextPositionRange is empty.

public bool IsEmpty { get; }

Property Value

bool:

true if the TextPositionRange is empty; otherwise, false.

IsNormalized

Gets whether the range is normalized (StartPosition occurs at or before the EndPosition).

public bool IsNormalized { get; }

Property Value

bool:

true if the range is normalized; otherwise, false.

IsZeroLength

Gets whether the range has a zero length.

public bool IsZeroLength { get; }

Property Value

bool:

true if the range has a zero length; otherwise, false.

LastPosition

Gets the last TextPosition in the range.

public TextPosition LastPosition { get; }

Property Value

TextPosition:

The last TextPosition in the range.

Remarks

This property returns either the StartPosition or EndPosition property, whichever comes last.

Lines

Gets the number of lines encompassed by the TextPositionRange.

public int Lines { get; }

Property Value

int:

The number of lines encompassed by the TextPositionRange.

NormalizedTextPositionRange

Gets a normalized version of this TextPositionRange without actually modifying this instance.

public TextPositionRange NormalizedTextPositionRange { get; }

Property Value

TextPositionRange:

A normalized version of this TextPositionRange without actually modifying this instance.

StartPosition

Gets the start TextPosition in the range.

public TextPosition StartPosition { get; }

Property Value

TextPosition:

The start TextPosition in the range.

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:

true if 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:

true if the TextPositionRange borders on, but does not overlap the specified TextPositionRange; otherwise, false.

Clone()

Creates a copy of this TextPositionRange object.

public object Clone()

Returns

object:

The TextPositionRange object that this method creates.

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:

true if 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:

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

ITextPositionRangeCollection:

The collection that was created.

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

ITextPositionRangeCollection:

The collection that was created.

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.

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:

true if 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:

true if the TextPositionRange intersects with the specified TextPositionRange; otherwise, false.

Invert()

Inverts the range by flipping the StartPosition and EndPosition values;

public void Invert()

Normalize()

Normalizes the range and ensures that the StartPosition occurs at or before the EndPositionTextPosition.

public void Normalize()

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:

true if the TextPositionRange overlaps with, or crosses, the specified TextPositionRange; otherwise, false.

ToString()

Converts the object to a String.

public override string ToString()

Returns

string:

A string whose value represents 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

TextPositionRange:

The normalized union of two TextPositionRange objects.

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:

true if the StartPosition and EndPosition values of left and right are 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:

true if the StartPosition and EndPosition values of left and right are unequal; otherwise, false.

Inherited Members