IniNode Class
Definition
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
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
Exceptions
- InvalidOperationException
Thrown when this node is not an object.
AsValue()
Returns this node as an IniValue.
public IniValue AsValue()
Returns
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
utf8IniReadOnlySpan<byte>The INI source bytes.
Returns
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
utf8IniReadOnlySpan<byte>The INI source bytes.
readerOptionsIniReaderOptionsThe source-order reader options.
documentOptionsIniDocumentOptionsThe document-model duplicate policies.
Returns
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
inistringThe INI source text.
Returns
Exceptions
- ArgumentNullException
Thrown when
iniis 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
writerUtf8IniWriterThe 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
valuestringThe string value.
Returns
Applies to
| Product | Versions |
|---|---|
| .NET | 8, 10 |