IniObject Class
Definition
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
namestringThe entry name.
Property Value
- IniNode
The node associated with
name.
Exceptions
- ArgumentNullException
Thrown when
nameor the assigned value is null.- KeyNotFoundException
Thrown by the getter when
nameis 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
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
namestringThe entry name.
Returns
Exceptions
- ArgumentNullException
Thrown when
nameis 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
namestringThe entry name.
Returns
Exceptions
- ArgumentNullException
Thrown when
nameis null.
TryGetValue(string, out IniNode?)
Attempts to get the node associated with the specified name.
public bool TryGetValue(string name, out IniNode? node)
Parameters
Returns
Exceptions
- ArgumentNullException
Thrown when
nameis null.
WriteTo(ref Utf8IniWriter)
Writes this node's INI representation to the supplied writer.
public override void WriteTo(ref Utf8IniWriter writer)
Parameters
writerUtf8IniWriterThe writer that receives the INI bytes.
Applies to
| Product | Versions |
|---|---|
| .NET | 8, 10 |