Class SourceDocumentPiece
Represents one piece of text in a PiecewiseSourceDocument.
public sealed class SourceDocumentPiece
- Inheritance
-
SourceDocumentPiece
- Inherited Members
Remarks
A piece can either expose text copied from an existing SourceSpan or literal generated text. Literal text may still have an anchor span so diagnostics in generated text can point back to the user-authored source that caused the text to exist.
Properties
Length
Gets the length of this piece in the assembled document.
public int Length { get; }
Property Value
- int
The length of this piece.
Origin
Gets the source span this piece came from or is anchored to.
public SourceSpan Origin { get; }
Property Value
- SourceSpan
The source span this piece came from or is anchored to.
ReadsFromOrigin
Gets a value indicating whether this piece reads its text from Origin instead of storing literal text.
public bool ReadsFromOrigin { get; }
Property Value
- bool
truewhen text is read from the origin span.
Text
public string Text { get; }
Property Value
Methods
FromSource(in SourceSpan)
Creates a piece whose text and source mapping both come from a source span.
public static SourceDocumentPiece FromSource(in SourceSpan origin)
Parameters
originSourceSpanThe source span to copy into the assembled document.
Returns
- SourceDocumentPiece
A source-backed piece.
FromText(string)
Creates a generated text piece with no known source provenance.
public static SourceDocumentPiece FromText(string text)
Parameters
textstringThe generated text.
Returns
- SourceDocumentPiece
A literal text piece.
FromText(string, in SourceSpan)
Creates a generated text piece anchored to a source span for diagnostics.
public static SourceDocumentPiece FromText(string text, in SourceSpan anchor)
Parameters
textstringThe generated text.
anchorSourceSpanThe span that caused the generated text to exist.
Returns
- SourceDocumentPiece
An anchored literal text piece.