Class StackMachineDocumentRenderer<T>
A handy base class for IDocumentRenderer<T> implementations which manage annotations in a stack.
Inheritance
- object
- StackMachineDocumentRenderer<T>
Implements
Inherited Members
- object.GetType()
- object.MemberwiseClone()
- object.ToString()
- object.Equals(object)
- object.Equals(object, object)
- object.ReferenceEquals(object, object)
- object.GetHashCode()
Declaration
public abstract class StackMachineDocumentRenderer<T> : IDocumentRenderer<T>
Type Parameters
Name | Description |
---|---|
T |
The type of annotations in the input Document<T>. |
Constructors
StackMachineDocumentRenderer()
A handy base class for IDocumentRenderer<T> implementations which manage annotations in a stack.
Declaration
protected StackMachineDocumentRenderer()
Properties
CurrentAnnotation
Get the topmost annotation from the stack, or return a default value.
Declaration
protected T? CurrentAnnotation { get; }
Property Value
Type | Description |
---|---|
T |
HasAnnotation
Returns true if there are annotations in the stack.
Declaration
protected bool HasAnnotation { get; }
Property Value
Type | Description |
---|---|
Stack
The stack of annotations.
Declaration
protected Stack<T> Stack { get; }
Property Value
Type | Description |
---|---|
Stack<T> |
Methods
NewLine(CancellationToken)
Write a line break into the output stream.
Declaration
public abstract ValueTask NewLine(CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
cancellationToken |
Returns
Type | Description |
---|---|
A ValueTask which will complete when the line break has been written to the output stream. |
OnBeforePopAnnotation(T, CancellationToken)
Called when value
is about to be
popped off the Stack.
Declaration
protected virtual ValueTask OnBeforePopAnnotation(T value, CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
T |
value |
The value. |
cancellationToken |
Returns
Type | Description |
---|---|
A ValueTask which will be awaited before
popping the |
Remarks
If the stack is mutated (by an override of this method) before the returned ValueTask completes, the value which is on top of the stack after the ValueTask resolves will be popped (and passed to OnPopAnnotation(T, CancellationToken)) instead.
OnBeforePushAnnotation(T, CancellationToken)
Called when value
is about to be
pushed onto the Stack.
Declaration
protected virtual ValueTask OnBeforePushAnnotation(T value, CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
T |
value |
The value. |
cancellationToken |
Returns
Type | Description |
---|---|
A ValueTask which will be awaited before
pushing the |
OnPopAnnotation(T, CancellationToken)
Called immediately after value
has been
popped off the Stack.
Declaration
protected virtual ValueTask OnPopAnnotation(T value, CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
T |
value |
The value. |
cancellationToken |
Returns
Type | Description |
---|---|
A ValueTask which will be awaited before returning from PopAnnotation(CancellationToken). |
OnPushAnnotation(T, CancellationToken)
Called immediately after value
has been
pushed onto the Stack.
Declaration
protected virtual ValueTask OnPushAnnotation(T value, CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
T |
value |
The value. |
cancellationToken |
Returns
Type | Description |
---|---|
A ValueTask which will be awaited before returning from PushAnnotation(T, CancellationToken). |
PopAnnotation(CancellationToken)
Discard the value of a previous call to PushAnnotation(T, CancellationToken).
Declaration
public virtual ValueTask PopAnnotation(CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
cancellationToken |
Returns
Type | Description |
---|---|
A ValueTask which will complete when the value has been popped from the stack. |
PushAnnotation(T, CancellationToken)
Accept an annotation.
Declaration
public virtual ValueTask PushAnnotation(T value, CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
T |
value |
The annotation to push onto the stack. |
cancellationToken |
Returns
Type | Description |
---|---|
A ValueTask which will complete when the value has been pushed onto the stack. |
Text(ReadOnlyMemory<char>, CancellationToken)
Write some text into the output stream.
Declaration
public abstract ValueTask Text(ReadOnlyMemory<char> memory, CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
memory |
The text to write to the output stream. |
|
cancellationToken |
Returns
Type | Description |
---|---|
A ValueTask which will complete when the text has been written to the output stream. |
WhiteSpace(int, CancellationToken)
Write the given amount
of
blank space into the output stream.
Declaration
public abstract ValueTask WhiteSpace(int amount, CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
amount |
The amount of white space to write. |
|
cancellationToken |
Returns
Type | Description |
---|---|
A ValueTask which will complete when the white space has been written to the output stream. |