Table of Contents

IniDocumentReader Struct

Definition

Namespace
Bodu.Text.Ini.Reader
Assembly
Bodu.Text.Ini.dll
Package
Bodu.Text.Ini 1.0.0
Source
IniDocumentReader.cs

Provides a forward-only cursor over the normalized token stream of a parsed INI document: a root object whose properties are the hoisted global keys followed by the sections, each section an object of key/value entries. The reader is a ref struct, so it cannot be boxed or captured.

public ref struct IniDocumentReader
Inherited Members

Remarks

INI cannot be normalized in a single forward pass when duplicate sections merge - a later [section] appends to an earlier one, declaring structure out of source order. The constructor therefore parses the entire document up front, applying the IniDocumentOptions duplicate policies, and Read() walks the materialized store. A malformed document or policy violation raises IniFormatException from the constructor rather than from Read(). This type walks a normalized document; Utf8IniReader reads the UTF-8 source in document order.

The stream is StartObject, the global PropertyName / String pairs, then for each section a PropertyName followed by a nested StartObject … EndObject, and a closing EndObject. Comments are not surfaced.

Constructors

IniDocumentReader(ReadOnlySpan<byte>)

Initializes a new instance of the IniDocumentReader struct over the supplied bytes using the default reader and document options.

public IniDocumentReader(ReadOnlySpan<byte> utf8Ini)

Parameters

utf8Ini ReadOnlySpan<byte>

The INI source bytes.

Exceptions

IniFormatException

Thrown when the bytes are not valid INI.

IniDocumentReader(ReadOnlySpan<byte>, IniReaderOptions, IniDocumentOptions)

Initializes a new instance of the IniDocumentReader struct over the supplied bytes using the supplied reader and document options.

public IniDocumentReader(ReadOnlySpan<byte> utf8Ini, IniReaderOptions readerOptions, IniDocumentOptions documentOptions)

Parameters

utf8Ini ReadOnlySpan<byte>

The INI source bytes.

readerOptions IniReaderOptions

The source-order reader options.

documentOptions IniDocumentOptions

The document-model duplicate policies.

Exceptions

IniFormatException

Thrown when the bytes are not valid INI, or when a duplicate section, duplicate key, or global-key/section-name collision violates the configured policies.

Properties

CurrentDepth

Gets the current container nesting depth.

public readonly int CurrentDepth { get; }

Property Value

int

The depth: zero at the document root, one inside a section object.

TokenType

Gets the kind of the current token.

public readonly IniTokenType TokenType { get; }

Property Value

IniTokenType

The current token kind, or None before the first or after the last token.

Methods

GetString()

Gets the text of the current token - a key name, section name, or string value.

public readonly string GetString()

Returns

string

The token text.

Exceptions

InvalidOperationException

Thrown when the current token has no text.

Read()

Advances the reader to the next token.

public bool Read()

Returns

bool

true when a token was read; false at the end of the document.

Applies to

ProductVersions
.NET8, 10