Table of Contents

IniNode Class

Definition

Namespace
Bodu.Text.Ini.Nodes
Assembly
Bodu.Text.Ini.dll
Package
Bodu.Text.Ini 1.0.0
Source
IniNode.cs

Represents a node in a mutable INI document tree. An INI document is a two-level object-of-objects: the root IniObject maps global keys to IniValue leaves and section names to section IniObject instances, and each section maps key names to IniValue leaves.

public abstract class IniNode
Inheritance
IniNode
Derived
Inherited Members
Extension Methods

Remarks

Unlike the other quartet DOMs, this tree deliberately bears comment trivia so that authoring and round-tripping are faithful: LeadingComments holds the comment lines that precede a node, and each IniObject additionally holds the trailing comment block at the end of its scope. Inline comments are not modeled - the reader dialect keeps everything after the assignment as part of the value, so an emitted inline comment would be re-read as value text.

Properties

LeadingComments

Gets the comment lines that precede this node, without their leading comment prefix character.

public IList<string> LeadingComments { get; }

Property Value

IList<string>

The mutable leading-comment list; empty when the node has no leading comments.

Remarks

Leading comments are emitted by the containing object when the node is written, each as one comment line. The outermost object written as a document emits no leading comments of its own; document-level trivia attaches to the first entry or section instead.

ValueKind

Gets the value kind of this node.

public abstract IniValueKind ValueKind { get; }

Property Value

IniValueKind

The node's IniValueKind.

Methods

AsObject()

Returns this node as an IniObject.

public IniObject AsObject()

Returns

IniObject

This node cast to IniObject.

Exceptions

InvalidOperationException

Thrown when this node is not an object.

AsValue()

Returns this node as an IniValue.

public IniValue AsValue()

Returns

IniValue

This node cast to IniValue.

Exceptions

InvalidOperationException

Thrown when this node is not a value.

DeepClone()

Creates a deep copy of this node, including its comment trivia.

public abstract IniNode DeepClone()

Returns

IniNode

The cloned node.

Parse(ReadOnlySpan<byte>)

Parses the supplied UTF-8 bytes into a mutable INI object tree using the default reader and document options.

public static IniObject Parse(ReadOnlySpan<byte> utf8Ini)

Parameters

utf8Ini ReadOnlySpan<byte>

The INI source bytes.

Returns

IniObject

The parsed IniObject root.

Exceptions

IniFormatException

Thrown when the bytes are not valid INI.

Parse(ReadOnlySpan<byte>, IniReaderOptions, IniDocumentOptions)

Parses the supplied UTF-8 bytes into a mutable INI object tree using the supplied reader and document options.

public static IniObject Parse(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.

Returns

IniObject

The parsed IniObject root.

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.

Parse(string)

Parses the supplied INI text into a mutable INI object tree.

public static IniObject Parse(string ini)

Parameters

ini string

The INI source text.

Returns

IniObject

The parsed IniObject root.

Exceptions

ArgumentNullException

Thrown when ini is null.

IniFormatException

Thrown when the text is not valid INI.

ToString()

Serializes this node to INI text.

public override string ToString()

Returns

string

The INI text.

ToUtf8Bytes()

Serializes this node to a new UTF-8 byte array.

public byte[] ToUtf8Bytes()

Returns

byte[]

The INI bytes.

WriteTo(ref Utf8IniWriter)

Writes this node's INI representation to the supplied writer.

public abstract void WriteTo(ref Utf8IniWriter writer)

Parameters

writer Utf8IniWriter

The writer that receives the INI bytes.

Operators

implicit operator IniNode(string)

Converts a string to an IniValue.

public static implicit operator IniNode(string value)

Parameters

value string

The string value.

Returns

IniNode

Applies to

ProductVersions
.NET8, 10