Class PiecewiseSourceDocument
Represents a derived source document assembled from ordered source and generated-text pieces.
public sealed class PiecewiseSourceDocument : DerivedSourceDocument
- Inheritance
-
PiecewiseSourceDocument
- Inherited Members
Remarks
Piecewise documents are useful for preprocessors, macro expansion, templating, REPL inputs, generated wrappers, and tests. They avoid storing one fully synthesized source string as the document's core representation: text is read from each piece as needed, and source resolution follows each piece back to its original source span or anchor.
Constructors
PiecewiseSourceDocument(string, IEnumerable<SourceDocumentPiece>)
Creates a piecewise source document from an identifier and pieces.
public PiecewiseSourceDocument(string identifier, IEnumerable<SourceDocumentPiece> pieces)
Parameters
identifierstringThe identifier for the assembled document.
piecesIEnumerable<SourceDocumentPiece>The pieces that make up the assembled document.
Properties
Identifier
Gets the document's identifier. This is typically a path.
public override string Identifier { get; }
Property Value
- string
The document's identifier.
Length
Gets the document's length, in characters.
public override int Length { get; }
Property Value
- int
The document's length.
Pieces
Gets the ordered pieces that make up this document.
public IReadOnlyList<SourceDocumentPiece> Pieces { get; }
Property Value
- IReadOnlyList<SourceDocumentPiece>
The ordered document pieces.
Methods
Create(string)
Creates a builder for a piecewise source document.
public static PiecewiseSourceDocumentBuilder Create(string identifier)
Parameters
identifierstringThe identifier for the assembled document.
Returns
- PiecewiseSourceDocumentBuilder
A piecewise source document builder.
GetText(int, int)
Gets a span of text in the document.
public override string GetText(int offset, int length)
Parameters
Returns
- string
A span of text.
Open(int)
Opens this source document at the given offset.
public override TextReader Open(int offset)
Parameters
offsetintThe offset to open the source document at.
Returns
- TextReader
A text reader.
ResolveSpan(int, int)
Resolves a span in this document to its original source coverage.
public override ResolvedSourceSpan ResolveSpan(int start, int length)
Parameters
startintThe zero-based start offset within this document.
lengthintThe span length within this document.
Returns
- ResolvedSourceSpan
The resolved original source coverage.