Skip to content

JsonElement.TryGetLineAndOffset Method

Definition

Namespace: Corvus.Text.Json
Assembly: Corvus.Text.Json.dll

Overloads

Method Description
TryGetLineAndOffset(int, int) Tries to get the 1-based line number and character offset of this element in the original source document.
TryGetLineAndOffset(int, int, long) Tries to get the 1-based line number, character offset, and byte offset of this element in the original source document.

TryGetLineAndOffset(int, int)

Source: JsonElement.SourceLocation.cs

Tries to get the 1-based line number and character offset of this element in the original source document.

public bool TryGetLineAndOffset(out int line, out int charOffset)

Parameters

Name Type Description
line int When this method returns, contains the 1-based line number if successful.
charOffset int When this method returns, contains the 1-based character offset within the line if successful.

Returns

bool

true if the line and offset were successfully determined; otherwise, false.

Remarks

This method returns false when the backing document does not retain the original source bytes (for example, mutable builder documents or fixed-string documents).

Applies To

Product Versions
.NET 9, 10
.NET Standard 2.0, 2.1

TryGetLineAndOffset(int, int, long)

Source: JsonElement.SourceLocation.cs

Tries to get the 1-based line number, character offset, and byte offset of this element in the original source document.

public bool TryGetLineAndOffset(out int line, out int charOffset, out long lineByteOffset)

Parameters

Name Type Description
line int When this method returns, contains the 1-based line number if successful.
charOffset int When this method returns, contains the 1-based character offset within the line if successful.
lineByteOffset long When this method returns, contains the byte offset of the start of the line if successful.

Returns

bool

true if the line and offset were successfully determined; otherwise, false.

Remarks

This method returns false when the backing document does not retain the original source bytes (for example, mutable builder documents or fixed-string documents).

Applies To

Product Versions
.NET 9, 10
.NET Standard 2.0, 2.1

Collaborate with us on GitHub

The source for this content can be found on GitHub, where you can also create and review issues and pull requests.

Open an issue