TextRange Struct
Represents a zero-based range of two offset values within a text document.
public struct TextRange : ICloneable, IComparable, ITextRangeProvider
- Implements:
- ICloneable IComparable ITextRangeProvider
Constructors
TextRange(Int32)
Initializes a new instance of the TextRange
class using the specified offset for both the start and end values.
public TextRange(int offset)
Parameter | Type | Description |
---|---|---|
offset | Int32 | The start and end offset in the range. |
TextRange(Int32, Int32)
Initializes a new instance of the TextRange
class with the specified offset values.
public TextRange(int startOffset, int endOffset)
Parameter | Type | Description |
---|---|---|
startOffset | Int32 | The start offset in the range. |
endOffset | Int32 | The end offset in the range. |
Properties
AbsoluteLength
Gets the absolute number of characters encompassed by the TextRange.
public int AbsoluteLength { get; }
Property Value
Remarks
This value will always return a positive length, even if the range is not normalized.
Deleted
Gets a TextRange that is flagged as deleted.
public static TextRange Deleted { get; }
Property Value
EndOffset
Gets the end offset in the range.
public int EndOffset { get; }
Property Value
- Int32:
The end offset in the range.
Remarks
The end offset may occur before the start offset if the range is not normalized. The IsNormalized property indicates if the range is normalized. To get the normalized first offset in the range, use the FirstOffset property. To get the normalized last offset in the range, use the LastOffset property.
FirstOffset
Gets the first offset in the range.
public int FirstOffset { get; }
Property Value
- Int32:
The first offset in the range.
Remarks
This property returns either the StartOffset or EndOffset property, whichever comes first.
IsDeleted
Gets whether the range has been flagged as deleted.
public bool IsDeleted { get; }
Property Value
- Boolean:
true
if the range has been flagged as deleted; otherwise,false
.
IsNormalized
Gets whether the range is normalized (StartOffset occurs at or before the EndOffset).
public bool IsNormalized { get; }
Property Value
- Boolean:
true
if the range is normalized; otherwise,false
.
IsZeroLength
Gets whether the range has a zero length.
public bool IsZeroLength { get; }
Property Value
- Boolean:
true
if the range has a zero length; otherwise,false
.
LastOffset
Gets the last offset in the range.
public int LastOffset { get; }
Property Value
- Int32:
The last offset in the range.
Remarks
This property returns either the StartOffset or EndOffset property, whichever comes last.
Length
Gets the number of characters encompassed by the TextRange.
public int Length { get; }
Property Value
Remarks
This value will return a negative length if the range is not normalized.
NormalizedTextRange
Gets a normalized version of this TextRange without actually modifying this instance.
public TextRange NormalizedTextRange { get; }
Property Value
StartOffset
Gets the start offset in the range.
public int StartOffset { get; }
Property Value
- Int32:
The start offset in the range.
Remarks
The start offset may occur after the end offset if the range is not normalized. The IsNormalized property indicates if the range is normalized. To get the normalized first offset in the range, use the FirstOffset property. To get the normalized last offset in the range, use the LastOffset property.
Methods
BordersOn(TextRange)
public bool BordersOn(TextRange range)
Parameter | Type | Description |
---|---|---|
range | TextRange | The TextRange to examine. |
Returns
BordersOn(Int32)
Returns whether the TextRange borders on the specified offset.
public bool BordersOn(int offset)
Parameter | Type | Description |
---|---|---|
offset | Int32 | The offset to examine. |
Returns
Remarks
This method checks to see if the specified offset is either the StartOffset or EndOffset.
Clone()
Creates a copy of this TextRange object.
CompareTo(TextRange)
Compares the current instance with another object of the same type.
public int CompareTo(TextRange textRange)
Parameter | Type | Description |
---|---|---|
textRange | TextRange | A TextRange to compare with this instance. |
Returns
- Int32:
A 32-bit signed integer that indicates the relative order of the comparands.
Contains(TextRange)
public bool Contains(TextRange range)
Parameter | Type | Description |
---|---|---|
range | TextRange | The TextRange to examine. |
Returns
Contains(Int32)
Returns whether the TextRange contains the specified offset.
public bool Contains(int offset)
Parameter | Type | Description |
---|---|---|
offset | Int32 | The offset to examine. |
Returns
Remarks
This method returns false
if the offset falls on the LastOffset offset
since this method indicates if the offset is encompassed by the TextRange.
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 |
Returns
- Boolean:
true
if the specifiedObject
is equal to the currentObject
; otherwise,false
.
FromSpan(Int32, Int32)
Returns a TextRange that covers the specified offset and length.
public static TextRange FromSpan(int offset, int length)
Parameter | Type | Description |
---|---|---|
offset | Int32 | The start offset. |
length | Int32 | The length of the range. |
Returns
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.
Intersect(TextRange, TextRange)
Returns the intersection of two TextRange objects.
public static TextRange Intersect(TextRange range1, TextRange range2)
Parameter | Type | Description |
---|---|---|
range1 | TextRange | The first TextRange to examine. |
range2 | TextRange | The second TextRange to examine. |
Returns
IntersectsWith(TextRange)
public bool IntersectsWith(TextRange range)
Parameter | Type | Description |
---|---|---|
range | TextRange | The TextRange to examine. |
Returns
Remarks
This method returns whether the specified TextRange borders on or overlaps the TextRange.
IntersectsWith(TextRange, Boolean, Boolean)
public bool IntersectsWith(TextRange range, bool includeFirstEdge, bool includeLastEdge)
Parameter | Type | Description |
---|---|---|
range | TextRange | The TextRange to examine. |
includeFirstEdge | Boolean | Whether to return |
includeLastEdge | Boolean | Whether to return |
Returns
Remarks
This method returns whether the specified TextRange borders on or overlaps the TextRange.
IntersectsWith(Int32)
Returns whether the TextRange intersects with the specified offset.
public bool IntersectsWith(int offset)
Parameter | Type | Description |
---|---|---|
offset | Int32 | The offset to examine. |
Returns
Remarks
This method returns whether the specified offset borders on or lies within the TextRange.
Invert()
Inverts the range by flipping the StartOffset and EndOffset values;
public void Invert()
Normalize()
Normalizes the range and ensures that the StartOffset occurs at or before the EndOffset offset.
public void Normalize()
OverlapsWith(TextRange)
public bool OverlapsWith(TextRange range)
Parameter | Type | Description |
---|---|---|
range | TextRange | The TextRange to examine. |
Returns
ToString()
Converts the object to a String
.
Translate(ITextSnapshot, ITextSnapshot, TextRangeTrackingModes)
Translates this text range from one ITextSnapshot to another in the same ITextDocument.
public TextRange Translate(ITextSnapshot fromSnapshot, ITextSnapshot toSnapshot, TextRangeTrackingModes trackingModes)
Parameter | Type | Description |
---|---|---|
fromSnapshot | ITextSnapshot | The ITextSnapshot to which to text range belongs. |
toSnapshot | ITextSnapshot | The ITextSnapshot that is the target of the translation. |
trackingModes | TextRangeTrackingModes | A TextRangeTrackingModes indicating the tracking modes to use. |
Returns
Translate(ITextVersion, ITextVersion, TextRangeTrackingModes)
Translates this text range from one ITextVersion to another in the same ITextDocument.
public TextRange Translate(ITextVersion fromVersion, ITextVersion toVersion, TextRangeTrackingModes trackingModes)
Parameter | Type | Description |
---|---|---|
fromVersion | ITextVersion | The ITextVersion to which to text range belongs. |
toVersion | ITextVersion | The ITextVersion that is the target of the translation. |
trackingModes | TextRangeTrackingModes | A TextRangeTrackingModes indicating the tracking modes to use. |
Returns
Union(TextRange, TextRange)
Returns the normalized union of two TextRange objects.
public static TextRange Union(TextRange range1, TextRange range2)
Parameter | Type | Description |
---|---|---|
range1 | TextRange | The first TextRange to examine. |
range2 | TextRange | The second TextRange to examine. |
Returns
Operators
Equality(TextRange, TextRange)
Compares two TextRange objects. The result specifies whether the values of the StartOffset and EndOffset properties of the two TextRange objects are equal.
public static bool operator ==(TextRange left, TextRange right)
Parameter | Type | Description |
---|---|---|
left | TextRange | A TextRange to compare. |
right | TextRange | A TextRange to compare. |
Returns
- Boolean:
true
if the StartOffset and EndOffset values ofleft
andright
are equal; otherwise,false
.
GreaterThan(TextRange, TextRange)
Compares whether one TextRange is greater than the other.
public static bool operator>(TextRange left, TextRange right)
Parameter | Type | Description |
---|---|---|
left | TextRange | A TextRange to compare. |
right | TextRange | A TextRange to compare. |
Returns
Inequality(TextRange, TextRange)
Compares two TextRange objects. The result specifies whether the values of the StartOffset and EndOffset properties of the two TextRange objects are unequal.
public static bool operator !=(TextRange left, TextRange right)
Parameter | Type | Description |
---|---|---|
left | TextRange | A TextRange to compare. |
right | TextRange | A TextRange to compare. |
Returns
- Boolean:
true
if the StartOffset and EndOffset values ofleft
andright
are unequal; otherwise,false
.
LessThan(TextRange, TextRange)
Compares whether one TextRange is less than the other.
public static bool operator <(TextRange left, TextRange right)
Parameter | Type | Description |
---|---|---|
left | TextRange | A TextRange to compare. |
right | TextRange | A TextRange to compare. |
Returns
Explicit Interface Implementations
ITextRangeProvider.TextRange
Gets or sets a TextRange that specifies the text range of the object.
TextRange ITextRangeProvider.TextRange { get; set; }
Returns
IComparable.CompareTo(Object)
Compares the current instance with another object of the same type.
int IComparable.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.