Struct TextSpan
Immutable abstract representation of a span of text. For example, in an error diagnostic that reports a location, it could come from a parsed string, text from a tool editor buffer, etc.
Inherited Members
Namespace: Loretta.CodeAnalysis.Text
Assembly: cs.temp.dll.dll
Syntax
public readonly struct TextSpan
Constructors
TextSpan(Int32, Int32)
Creates a TextSpan instance beginning with the position Start and having the Length
specified with length.
Declaration
public TextSpan(int start, int length)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Int32 | start | |
| System.Int32 | length |
Properties
End
End of the span.
Declaration
public readonly int End { get; }
Property Value
| Type | Description |
|---|---|
| System.Int32 |
IsEmpty
Determines whether or not the span is empty.
Declaration
public readonly bool IsEmpty { get; }
Property Value
| Type | Description |
|---|---|
| System.Boolean |
Length
Length of the span.
Declaration
public readonly int Length { get; }
Property Value
| Type | Description |
|---|---|
| System.Int32 |
Start
Start point of the span.
Declaration
public readonly int Start { get; }
Property Value
| Type | Description |
|---|---|
| System.Int32 |
Methods
CompareTo(TextSpan)
Compares current instance of TextSpan with another.
Declaration
public readonly int CompareTo(TextSpan other)
Parameters
| Type | Name | Description |
|---|---|---|
| TextSpan | other |
Returns
| Type | Description |
|---|---|
| System.Int32 |
Contains(TextSpan)
Determines whether span falls completely within this span.
Declaration
public readonly bool Contains(TextSpan span)
Parameters
| Type | Name | Description |
|---|---|---|
| TextSpan | span | The span to check. |
Returns
| Type | Description |
|---|---|
| System.Boolean |
|
Contains(Int32)
Determines whether the position lies within the span.
Declaration
public readonly bool Contains(int position)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Int32 | position | The position to check. |
Returns
| Type | Description |
|---|---|
| System.Boolean |
|
Equals(TextSpan)
Determines if current instance of TextSpan is equal to another.
Declaration
public readonly bool Equals(TextSpan other)
Parameters
| Type | Name | Description |
|---|---|---|
| TextSpan | other |
Returns
| Type | Description |
|---|---|
| System.Boolean |
Equals(Object)
Determines if current instance of TextSpan is equal to another.
Declaration
public override readonly bool Equals(object obj)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Object | obj |
Returns
| Type | Description |
|---|---|
| System.Boolean |
Overrides
FromBounds(Int32, Int32)
Creates a new TextSpan from start and end positions as opposed to a position and length.
The returned TextSpan contains the range with start inclusive,
and end exclusive.
Declaration
public static TextSpan FromBounds(int start, int end)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Int32 | start | |
| System.Int32 | end |
Returns
| Type | Description |
|---|---|
| TextSpan |
GetHashCode()
Produces a hash code for TextSpan.
Declaration
public override readonly int GetHashCode()
Returns
| Type | Description |
|---|---|
| System.Int32 |
Overrides
Intersection(TextSpan)
Returns the intersection with the given span, or null if there is no intersection.
Declaration
public readonly TextSpan? Intersection(TextSpan span)
Parameters
| Type | Name | Description |
|---|---|---|
| TextSpan | span | The span to check. |
Returns
| Type | Description |
|---|---|
| System.Nullable<TextSpan> | The intersection of the spans, or null if the intersection is empty. |
IntersectsWith(TextSpan)
Determines whether span intersects this span. Two spans are considered to
intersect if they have positions in common or the end of one span
coincides with the start of the other span.
Declaration
public readonly bool IntersectsWith(TextSpan span)
Parameters
| Type | Name | Description |
|---|---|---|
| TextSpan | span | The span to check. |
Returns
| Type | Description |
|---|---|
| System.Boolean |
|
IntersectsWith(Int32)
Determines whether position intersects this span.
A position is considered to intersect if it is between the start and
end positions (inclusive) of this span.
Declaration
public readonly bool IntersectsWith(int position)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Int32 | position | The position to check. |
Returns
| Type | Description |
|---|---|
| System.Boolean |
|
Overlap(TextSpan)
Returns the overlap with the given span, or null if there is no overlap.
Declaration
public readonly TextSpan? Overlap(TextSpan span)
Parameters
| Type | Name | Description |
|---|---|---|
| TextSpan | span | The span to check. |
Returns
| Type | Description |
|---|---|
| System.Nullable<TextSpan> | The overlap of the spans, or null if the overlap is empty. |
OverlapsWith(TextSpan)
Determines whether span overlaps this span. Two spans are considered to overlap
if they have positions in common and neither is empty. Empty spans do not overlap with any
other span.
Declaration
public readonly bool OverlapsWith(TextSpan span)
Parameters
| Type | Name | Description |
|---|---|---|
| TextSpan | span | The span to check. |
Returns
| Type | Description |
|---|---|
| System.Boolean |
|
ToString()
Provides a string representation for TextSpan.
Declaration
public override readonly string ToString()
Returns
| Type | Description |
|---|---|
| System.String |
Overrides
Operators
Equality(TextSpan, TextSpan)
Determines if two instances of TextSpan are the same.
Declaration
public static bool operator ==(TextSpan left, TextSpan right)
Parameters
| Type | Name | Description |
|---|---|---|
| TextSpan | left | |
| TextSpan | right |
Returns
| Type | Description |
|---|---|
| System.Boolean |
Inequality(TextSpan, TextSpan)
Determines if two instances of TextSpan are different.
Declaration
public static bool operator !=(TextSpan left, TextSpan right)
Parameters
| Type | Name | Description |
|---|---|---|
| TextSpan | left | |
| TextSpan | right |
Returns
| Type | Description |
|---|---|
| System.Boolean |