Location Class

Represents where something was found in source: a character range and, when it is known, the text that range indexes into.

public sealed class Location : IEquatable<Location>

Example

var text = "one\ntwo\nthree line here";
var location = new Location(new TextSpan(15, 7), SourceText.From(text));

// Lines and columns are zero-based
Assert.Equal("(2,7)-(2,14)", location.ToString());
Assert.Equal(2, location.GetLineSpan().Start.Line);
Implements

Constructors

NameDescription
Location(TextSpan, SourceText?)

Location(TextSpan, SourceText?)

Location.cs
public Location(TextSpan sourceSpan, SourceText? sourceText = null)

Parameters

sourceSpan TextSpan
sourceText SourceText?

No documentation is available.

Properties

NameDescription
NoneA location that points at no text.
SourceSpanThe character range this location covers.
SourceTextThe text Location.SourceSpan indexes into, or null when the location is not bound to any text.

A location that points at no text.

public static Location None { get; }

Property value

Location

SourceSpan

Location.cs

The character range this location covers.

public TextSpan SourceSpan { get; }

Property value

TextSpan

SourceText

Location.cs

The text Location.SourceSpan indexes into, or null when the location is not bound to any text.

public SourceText? SourceText { get; }

Property value

SourceText?

Methods

NameDescription
Equals(Location?)Compares the span by value and the source text by reference, so two locations are equal only when they point at the same range of the same text.
Equals(object?)
GetHashCode()
GetLineSpan()Maps Location.SourceSpan onto line and character positions. Returns default when Location.SourceText is null.
ToString()Returns the line span, or the character range when the location is not bound to any text.

Equals overloads

Equals(Location?)

Location.cs

Compares the span by value and the source text by reference, so two locations are equal only when they point at the same range of the same text.

public bool Equals(Location? other)
Parameters
other Location?
Returns

bool

Equals(object?)

Location.cs
public override bool Equals(object? obj)
Parameters
obj object?
Returns

bool

No documentation is available.

GetHashCode()

Location.cs
public override int GetHashCode()

Returns

int

No documentation is available.

GetLineSpan()

Location.cs

Maps Location.SourceSpan onto line and character positions. Returns default when Location.SourceText is null.

public LinePositionSpan GetLineSpan()

ToString()

Location.cs

Returns the line span, or the character range when the location is not bound to any text.

public override string ToString()

Returns

string