In This Article

TextSnapshotRange Struct

Represents a zero-based range of two normalized offset values within a certain ITextSnapshot.

public struct TextSnapshotRange : ITextPositionRangeProvider, ITextRangeProvider
Implements:
ITextPositionRangeProvider ITextRangeProvider

Constructors

TextSnapshotRange(ITextSnapshot, TextRange)

Initializes a new instance of the TextSnapshotRange class with the specified TextRange.

public TextSnapshotRange(ITextSnapshot snapshot, TextRange textRange)
Parameter Type Description
snapshot ITextSnapshot

The ITextSnapshot that contains the text range.

textRange TextRange

The TextRange of the range.

TextSnapshotRange(ITextSnapshot, int)

Initializes a new instance of the TextSnapshotRange class using the specified offset for both the start and end values.

public TextSnapshotRange(ITextSnapshot snapshot, int offset)
Parameter Type Description
snapshot ITextSnapshot

The ITextSnapshot that contains the text range.

offset int

The start and end offset in the range.

TextSnapshotRange(ITextSnapshot, int, int)

Initializes a new instance of the TextSnapshotRange class with the specified offset values.

public TextSnapshotRange(ITextSnapshot snapshot, int startOffset, int endOffset)
Parameter Type Description
snapshot ITextSnapshot

The ITextSnapshot that contains the text range.

startOffset int

The start offset in the range.

endOffset int

The end offset in the range.

TextSnapshotRange(TextSnapshotOffset)

Initializes a new instance of the TextSnapshotRange class using the specified TextSnapshotOffset for both the start and end values.

public TextSnapshotRange(TextSnapshotOffset snapshotOffset)
Parameter Type Description
snapshotOffset TextSnapshotOffset

The start and end offset in the range.

Properties

AbsoluteLength

Gets the absolute number of characters encompassed by the TextSnapshotRange.

public int AbsoluteLength { get; }

Property Value

int:

The absolute number of characters encompassed by the TextSnapshotRange.

Remarks

This value will always return a positive length, even if the range is not normalized.

Deleted

Gets a TextSnapshotRange that has no Snapshot and is flagged as deleted.

public static TextSnapshotRange Deleted { get; }

Property Value

TextSnapshotRange:

A TextSnapshotRange that has no Snapshot and is flagged as deleted.

EndLine

Gets the ITextSnapshotLine that contains the end offset in the text range.

public ITextSnapshotLine EndLine { get; }

Property Value

ITextSnapshotLine:

The ITextSnapshotLine that contains the end offset in the text range.

EndOffset

Gets the end offset in the range.

public int EndOffset { get; }

Property Value

int:

The end offset in the range.

Remarks

Since snapshot ranges are normalized, this property returns the last offset in the range.

EndPosition

Gets the end TextPosition in the range.

public TextPosition EndPosition { get; }

Property Value

TextPosition:

The end TextPosition in the range.

Remarks

Since snapshot ranges are normalized, this property returns the last TextPosition in the range.

IsDeleted

Gets whether the range has been flagged as deleted.

public bool IsDeleted { get; }

Property Value

bool:

true if the range has been flagged as deleted; 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.

Length

Gets the number of characters encompassed by the TextSnapshotRange.

public int Length { get; }

Property Value

int:

The number of characters encompassed by the TextSnapshotRange.

Remarks

This value will return a negative length if the range is not normalized.

PositionRange

Gets a TextPositionRange that specifies the text position range of the object.

public TextPositionRange PositionRange { get; }

Property Value

TextPositionRange:

A TextPositionRange that specifies the text position range of the object.

Snapshot

Gets the ITextSnapshot that contains the text range.

public ITextSnapshot Snapshot { get; }

Property Value

ITextSnapshot:

The ITextSnapshot that contains the text range.

StartLine

Gets the ITextSnapshotLine that contains the start offset in the text range.

public ITextSnapshotLine StartLine { get; }

Property Value

ITextSnapshotLine:

The ITextSnapshotLine that contains the start offset in the text range.

StartOffset

Gets the start offset in the range.

public int StartOffset { get; }

Property Value

int:

The start offset in the range.

Remarks

Since snapshot ranges are normalized, this property returns the first offset in the range.

StartPosition

Gets the start TextPosition in the range.

public TextPosition StartPosition { get; }

Property Value

TextPosition:

The start TextPosition in the range.

Remarks

Since snapshot ranges are normalized, this property returns the first TextPosition in the range.

Text

Gets the snapshot text substring encompassed by this range, using CarriageReturnNewline for line ends.

public string Text { get; }

Property Value

string:

The snapshot text substring encompassed by this range, using CarriageReturnNewline for line ends.

TextRange

Gets a TextRange that specifies the text range of the object.

public TextRange TextRange { get; }

Property Value

TextRange:

A TextRange that specifies the text range of the object.

Methods

BordersOn(TextRange)

Returns whether the TextSnapshotRange borders on, but does not overlap the specified TextRange.

public bool BordersOn(TextRange range)
Parameter Type Description
range TextRange

The TextRange to examine.

Returns

bool:

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

BordersOn(TextSnapshotRange)

Returns whether the TextSnapshotRange borders on, but does not overlap the specified TextSnapshotRange.

public bool BordersOn(TextSnapshotRange range)
Parameter Type Description
range TextSnapshotRange

The TextSnapshotRange to examine.

Returns

bool:

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

BordersOn(int)

Returns whether the TextSnapshotRange borders on the specified offset.

public bool BordersOn(int offset)
Parameter Type Description
offset int

The offset to examine.

Returns

bool:

true if the TextSnapshotRange borders on the specified offset; otherwise, false.

Remarks

This method checks to see if the specified offset is either the StartOffset or EndOffset.

CompareTo(TextRange)

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

public int CompareTo(TextRange range)
Parameter Type Description
range TextRange

A TextRange to compare with this instance.

Returns

int:

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

CompareTo(TextSnapshotRange)

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

public int CompareTo(TextSnapshotRange range)
Parameter Type Description
range TextSnapshotRange

A TextSnapshotRange to compare with this instance.

Returns

int:

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

Contains(TextRange)

Returns whether the TextSnapshotRange contains the specified TextRange.

public bool Contains(TextRange range)
Parameter Type Description
range TextRange

The TextRange to examine.

Returns

bool:

true if the TextSnapshotRange contains the specified TextRange; otherwise, false.

Contains(TextSnapshotRange)

Returns whether the TextSnapshotRange contains the specified TextSnapshotRange.

public bool Contains(TextSnapshotRange range)
Parameter Type Description
range TextSnapshotRange

The TextSnapshotRange to examine.

Returns

bool:

true if the TextSnapshotRange contains the specified TextSnapshotRange; otherwise, false.

Contains(int)

Returns whether the TextSnapshotRange contains the specified offset.

public bool Contains(int offset)
Parameter Type Description
offset int

The offset to examine.

Returns

bool:

true if the TextSnapshotRange contains the specified offset; otherwise, false.

Remarks

This method returns false if the offset falls on the EndOffset offset since this method indicates if the offset is encompassed by the TextSnapshotRange.

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.

FromSpan(ITextSnapshot, int, int)

Returns a TextSnapshotRange that covers the specified offset and length.

public static TextSnapshotRange FromSpan(ITextSnapshot snapshot, int offset, int length)
Parameter Type Description
snapshot ITextSnapshot

The ITextSnapshot that contains the text range.

offset int

The start offset.

length int

The length of the range.

Returns

TextSnapshotRange:

The TextSnapshotRange that was created.

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.

GetText(LineTerminator)

Returns the snapshot text substring encompassed by this range, using the specified LineTerminator for line ends.

public string GetText(LineTerminator lineTerminator)
Parameter Type Description
lineTerminator LineTerminator

A LineTerminator specifying the type of line terminators to use.

Returns

string:

The snapshot text substring encompassed by this range, using the specified LineTerminator for line ends.

IntersectsWith(TextRange)

Returns whether the TextSnapshotRange intersects with the specified TextRange.

public bool IntersectsWith(TextRange range)
Parameter Type Description
range TextRange

The TextRange to examine.

Returns

bool:

true if the TextSnapshotRange intersects with the specified TextRange; otherwise, false.

Remarks

This method returns whether the specified TextRange borders on or overlaps the TextSnapshotRange.

IntersectsWith(TextSnapshotRange)

Returns whether the TextSnapshotRange intersects with the specified TextSnapshotRange.

public bool IntersectsWith(TextSnapshotRange range)
Parameter Type Description
range TextSnapshotRange

The TextSnapshotRange to examine.

Returns

bool:

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

Remarks

This method returns whether the specified TextSnapshotRange borders on or overlaps the TextSnapshotRange.

IntersectsWith(TextSnapshotRange, bool, bool)

Returns whether the TextSnapshotRange intersects with the specified TextSnapshotRange.

public bool IntersectsWith(TextSnapshotRange range, bool includeFirstEdge, bool includeLastEdge)
Parameter Type Description
range TextSnapshotRange

The TextSnapshotRange to examine.

includeFirstEdge bool

Whether to return true if the specified TextSnapshotRange borders on the leading (first) edge of this TextSnapshotRange.

includeLastEdge bool

Whether to return true if the specified TextSnapshotRange borders on the trailing (last) edge of this TextSnapshotRange.

Returns

bool:

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

Remarks

This method returns whether the specified TextSnapshotRange borders on or overlaps the TextSnapshotRange.

IntersectsWith(int)

Returns whether the TextSnapshotRange intersects with the specified offset.

public bool IntersectsWith(int offset)
Parameter Type Description
offset int

The offset to examine.

Returns

bool:

true if the TextSnapshotRange intersects with the specified offset; otherwise, false.

Remarks

This method returns whether the specified offset borders on or lies within the TextSnapshotRange.

OverlapsWith(TextRange)

Returns whether the TextSnapshotRange overlaps with, or crosses, the specified TextRange.

public bool OverlapsWith(TextRange range)
Parameter Type Description
range TextRange

The TextRange to examine.

Returns

bool:

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

OverlapsWith(TextSnapshotRange)

Returns whether the TextSnapshotRange overlaps with, or crosses, the specified TextSnapshotRange.

public bool OverlapsWith(TextSnapshotRange range)
Parameter Type Description
range TextSnapshotRange

The TextSnapshotRange to examine.

Returns

bool:

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

ToString()

Converts the object to a String.

public override string ToString()

Returns

string:

A string whose value represents this object.

ToVersionRange(TextRangeTrackingModes)

Converts this text range into an ITextVersionRange.

public ITextVersionRange ToVersionRange(TextRangeTrackingModes trackingModes)
Parameter Type Description
trackingModes TextRangeTrackingModes

A TextRangeTrackingModes indicating the tracking modes to use.

Returns

ITextVersionRange:

The ITextVersionRange that was created.

ToVersionRange(Func<TextRangeTrackingModes>)

Converts this text range into an ITextVersionRange.

public ITextVersionRange ToVersionRange(Func<TextRangeTrackingModes> trackingModesFunc)
Parameter Type Description
trackingModesFunc Func<TextRangeTrackingModes>

A function that dynamically returns a TextRangeTrackingModes indicating the tracking modes to use.

Returns

ITextVersionRange:

The ITextVersionRange that was created.

TranslateTo(ITextSnapshot, TextRangeTrackingModes)

Translates this text range from one ITextSnapshot to another in the same ITextDocument.

public TextSnapshotRange TranslateTo(ITextSnapshot toSnapshot, TextRangeTrackingModes trackingModes)
Parameter Type Description
toSnapshot ITextSnapshot

The ITextSnapshot that is the target of the translation.

trackingModes TextRangeTrackingModes

A TextRangeTrackingModes indicating the tracking modes to use.

Returns

TextSnapshotRange:

The translated TextSnapshotRange.

Operators

operator ==(TextSnapshotRange, TextSnapshotRange)

Compares two TextSnapshotRange objects. The result specifies whether the values of the StartOffset and EndOffset properties of the two TextSnapshotRange objects are equal.

public static bool operator ==(TextSnapshotRange left, TextSnapshotRange right)
Parameter Type Description
left TextSnapshotRange

A TextSnapshotRange to compare.

right TextSnapshotRange

A TextSnapshotRange to compare.

Returns

bool:

true if the StartOffset and EndOffset values of left and right are equal; otherwise, false.

operator >(TextSnapshotRange, TextSnapshotRange)

Compares whether one TextSnapshotRange is greater than the other.

public static bool operator >(TextSnapshotRange left, TextSnapshotRange right)
Parameter Type Description
left TextSnapshotRange

A TextSnapshotRange to compare.

right TextSnapshotRange

A TextSnapshotRange to compare.

Returns

bool:

true if the TextSnapshotRange in left is greater than the TextSnapshotRange in right; otherwise, false.

implicit operator TextRange(TextSnapshotRange)

Implicitly converts a TextSnapshotRange instance to a TextRange.

public static implicit operator TextRange(TextSnapshotRange range)
Parameter Type Description
range TextSnapshotRange

The TextSnapshotRange to convert.

Returns

TextRange:

The TextRange result.

operator !=(TextSnapshotRange, TextSnapshotRange)

Compares two TextSnapshotRange objects. The result specifies whether the values of the StartOffset and EndOffset properties of the two TextSnapshotRange objects are unequal.

public static bool operator !=(TextSnapshotRange left, TextSnapshotRange right)
Parameter Type Description
left TextSnapshotRange

A TextSnapshotRange to compare.

right TextSnapshotRange

A TextSnapshotRange to compare.

Returns

bool:

true if the StartOffset and EndOffset values of left and right are unequal; otherwise, false.

operator <(TextSnapshotRange, TextSnapshotRange)

Compares whether one TextSnapshotRange is less than the other.

public static bool operator <(TextSnapshotRange left, TextSnapshotRange right)
Parameter Type Description
left TextSnapshotRange

A TextSnapshotRange to compare.

right TextSnapshotRange

A TextSnapshotRange to compare.

Returns

bool:

true if the TextSnapshotRange in left is less than the TextSnapshotRange in right; otherwise, false.

Inherited Members