Struct SourceRange
A contiguous span in a source document, from a Start position (inclusive) to an End position (exclusive).
public readonly record struct SourceRange : IComparable<SourceRange>, IEquatable<SourceRange>
- Implements
- Inherited Members
Remarks
IComparable compares source location start.
Constructors
SourceRange(SourcePosition, SourcePosition)
A contiguous span in a source document, from a Start position (inclusive) to an End position (exclusive).
public SourceRange(SourcePosition Start, SourcePosition End)
Parameters
StartSourcePositionThe inclusive start position of the range.
EndSourcePositionThe exclusive end position of the range.
Remarks
IComparable compares source location start.
SourceRange(int, int, int, int)
Creates a SourceRange from zero-based start/end line numbers and character offsets.
public SourceRange(int startLine, int startCharacter, int endLine, int endCharacter)
Parameters
Properties
Empty
Gets an empty range at position L0C0.
public static SourceRange Empty { get; }
Property Value
End
The exclusive end position of the range.
public SourcePosition End { get; init; }
Property Value
IsEmpty
true if this range spans no characters (Start and End are the same position).
public bool IsEmpty { get; }
Property Value
Start
The inclusive start position of the range.
public SourcePosition Start { get; init; }
Property Value
Methods
CompareTo(SourceRange)
Compares two ranges by where they start, in document order.
public int CompareTo(SourceRange other)
Parameters
otherSourceRangeThe range to compare with.
Returns
- int
Less than zero when this range starts before
other, zero when they start at the same position, greater than zero when it starts after.
Contains(SourcePosition)
Whether a position is in the range: at its Start, or after it and before its End, which is not in it.
public bool Contains(SourcePosition position)
Parameters
positionSourcePositionThe position.
Returns
Contains(SourceRange)
public bool Contains(SourceRange range)
Parameters
rangeSourceRangeThe other range.
Returns
- bool
true when every character of
rangeis in this range. An empty range is within this one when its position is from Start to End, both included; a range is within itself.
Intersects(SourceRange)
Whether this range and another share a character: each starts before the other ends.
public bool Intersects(SourceRange range)
Parameters
rangeSourceRangeThe other range.