EventReader Class

Reads events from a sequence of ParsingEvent.

public class EventReader

Constructors

NameDescription
EventReader(IParser)Initializes a new instance of the EventReader class.

EventReader(IParser)

EventReader.cs

Initializes a new instance of the EventReader class.

public EventReader(IParser parser)

Parameters

parser IParser
The parser that provides the events.

Properties

NameDescription
CurrentDepthGets or sets current Depth.
ParserGets the underlying parser.

CurrentDepth

EventReader.cs

Gets or sets current Depth.

public int CurrentDepth { get; }

Property value

int

Gets the underlying parser.

public IParser Parser { get; }

Property value

IParser The parser.

Methods

NameDescription
Accept<T>()Checks whether the current event is of the specified type.
Allow<T>()Checks whether the current event is of the specified type. If the event is of the specified type, returns it and moves to the next event. Otherwise retruns null.
Expect<T>()Ensures that the current event is of the specified type, returns it and moves to the next event.
Peek<T>()Gets the next event without consuming it.
Skip()Skips the current event and any "child" event.
Skip(int)Skips until we reach the appropriate depth again

Accept<T>()

EventReader.cs

Checks whether the current event is of the specified type.

public bool Accept<T>() where T : ParsingEvent

Type parameters

T
Type of the event.

Returns

bool Returns true if the current event is of type T. Otherwise returns false.

Allow<T>()

EventReader.cs

Checks whether the current event is of the specified type. If the event is of the specified type, returns it and moves to the next event. Otherwise retruns null.

public T? Allow<T>() where T : ParsingEvent

Type parameters

T
Type of the ParsingEvent.

Returns

T? Returns the current event if it is of type T; otherwise returns null.

Expect<T>()

EventReader.cs

Ensures that the current event is of the specified type, returns it and moves to the next event.

public T Expect<T>() where T : ParsingEvent

Type parameters

T
Type of the ParsingEvent.

Returns

T Returns the current event.

Exceptions

YamlException
If the current event is not of the specified type.

Gets the next event without consuming it.

public T? Peek<T>() where T : ParsingEvent

Type parameters

T
Type of the ParsingEvent.

Returns

T? Returns the current event if it is of type T; otherwise returns null.

Skip overloads

Skips the current event and any "child" event.

public void Skip()

Skips until we reach the appropriate depth again

public void Skip(int untilDepth)
Parameters
untilDepth int