Table of Contents

IniObject Class

Definition

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

Represents an object in a mutable INI document tree: an insertion-ordered map of names to nodes. The document root maps global keys to IniValue leaves and section names to section IniObject instances; a section maps key names to IniValue leaves only.

public sealed class IniObject : IniNode
Inheritance
IniObject
Inherited Members
Extension Methods

Remarks

INI is physically two-level, so depth is enforced when the tree is written: an IniObject nested inside a section raises InvalidOperationException from WriteTo(ref Utf8IniWriter).

When the root is written, its IniValue entries are emitted before its section objects regardless of insertion interleave - a key emitted after a section header would be re-read as belonging to that section, so the global entries must precede the first header.

Constructors

IniObject()

Initializes a new instance of the IniObject class.

public IniObject()

Properties

Count

Gets the number of entries in this object.

public int Count { get; }

Property Value

int

The entry count.

this[string]

Gets or sets the node associated with the specified name, adding the name at the end when it is new and preserving its position when it already exists.

public IniNode this[string name] { get; set; }

Parameters

name string

The entry name.

Property Value

IniNode

The node associated with name.

Exceptions

ArgumentNullException

Thrown when name or the assigned value is null.

KeyNotFoundException

Thrown by the getter when name is not present.

Keys

Gets the entry names in insertion order.

public IReadOnlyList<string> Keys { get; }

Property Value

IReadOnlyList<string>

The ordered entry names.

TrailingComments

Gets the comment lines at the end of this object's scope, without their leading comment prefix character.

public IList<string> TrailingComments { get; }

Property Value

IList<string>

The mutable trailing-comment list; empty when the scope ends without a comment block.

Remarks

When parsing, comment lines that are not followed by another section or entry - the block at the end of the document - attach here on the innermost object being read. When writing, the block is emitted after the object's entries.

ValueKind

Gets the value kind of this node.

public override IniValueKind ValueKind { get; }

Property Value

IniValueKind

The node's IniValueKind.

Methods

ContainsKey(string)

Determines whether this object contains the specified name.

public bool ContainsKey(string name)

Parameters

name string

The entry name.

Returns

bool

true when the name is present; otherwise false.

Exceptions

ArgumentNullException

Thrown when name is null.

DeepClone()

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

public override IniNode DeepClone()

Returns

IniNode

The cloned node.

Remove(string)

Removes the entry with the specified name.

public bool Remove(string name)

Parameters

name string

The entry name.

Returns

bool

true when an entry was removed; otherwise false.

Exceptions

ArgumentNullException

Thrown when name is null.

TryGetValue(string, out IniNode?)

Attempts to get the node associated with the specified name.

public bool TryGetValue(string name, out IniNode? node)

Parameters

name string

The entry name.

node IniNode

When this method returns true, the node; otherwise null.

Returns

bool

true when the name is present; otherwise false.

Exceptions

ArgumentNullException

Thrown when name is null.

WriteTo(ref Utf8IniWriter)

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

public override void WriteTo(ref Utf8IniWriter writer)

Parameters

writer Utf8IniWriter

The writer that receives the INI bytes.

Applies to

ProductVersions
.NET8, 10