Table of Contents

IniDocumentBase Class

Definition

Namespace
Bodu.Text.Configuration
Assembly
Bodu.Text.Configuration.dll
Package
Bodu.Text.Configuration 1.0.0
Source
IniDocumentBase.cs

Provides the shared, read-oriented model for an INI-style document: a global section plus an ordered set of named sections, with name-based lookup. Serves as the common base for the mutable IniDocument and for configuration-layer document types that expose only a read surface.

public abstract class IniDocumentBase
Inheritance
IniDocumentBase
Derived
Inherited Members
Extension Methods

Remarks

The public surface of IniDocumentBase is read-only: it exposes GlobalSection, Sections, and the GetSection(string)/ TryGetSection(string, out IniSection?) lookups. Mutation is reserved to derived types through the protected core methods (AddSectionCore(IniSection), GetOrAddSectionCore(string), RemoveSectionCore(string)); a concrete subclass chooses whether to re-expose them publicly.

Section lookup uses ordinal comparison, case-insensitive by default and case-sensitive when the document was created with that option.

Constructors

IniDocumentBase(IniSection, IEnumerable<IniSection>, bool)

Initializes a new instance of the IniDocumentBase class from a global section and an ordered sequence of named sections.

protected IniDocumentBase(IniSection globalSection, IEnumerable<IniSection> sections, bool caseSensitiveSections)

Parameters

globalSection IniSection

The global section (entries authored before the first named section header). Its Name must be the empty string.

sections IEnumerable<IniSection>

The ordered, named sections that follow the global section.

caseSensitiveSections bool

true to compare section names with ordinal case sensitivity; otherwise, false (the INI default).

Exceptions

ArgumentNullException

Thrown when globalSection or sections is null.

ArgumentException

Thrown when globalSection has a non-empty Name, or when sections contains a null entry.

IniDocumentBase(bool)

Initializes a new instance of the IniDocumentBase class with an empty global section and no named sections.

protected IniDocumentBase(bool caseSensitiveSections)

Parameters

caseSensitiveSections bool

true to compare section names with ordinal case sensitivity; otherwise, false (the INI default).

Properties

GlobalSection

Gets the global section, which contains any key/value entries that appeared before the first named section header.

public IniSection GlobalSection { get; }

Property Value

IniSection

An IniSection whose Name is the empty string. Never null; its Entries list is empty when the source contained no pre-section keys.

Sections

Gets the named sections in the order they first appeared in the source.

public IReadOnlyList<IniSection> Sections { get; }

Property Value

IReadOnlyList<IniSection>

A read-only list of IniSection instances. Does not include GlobalSection.

Methods

AddSectionCore(IniSection)

Appends section to the document. Intended for use by derived types that expose a mutation surface.

protected void AddSectionCore(IniSection section)

Parameters

section IniSection

The section to append.

Exceptions

ArgumentNullException

section is null.

ArgumentException

section has an empty Name (i.e. it is the global section).

GetOrAddSectionCore(string)

Returns the first section with the supplied name, creating and appending one when no match exists. Intended for use by derived types that expose a mutation surface.

protected IniSection GetOrAddSectionCore(string name)

Parameters

name string

The section name.

Returns

IniSection

The matching or newly created section.

Exceptions

ArgumentNullException

name is null.

ArgumentException

name is empty.

GetSection(string)

Gets the named section with the specified name, or null if it is absent.

public IniSection? GetSection(string name)

Parameters

name string

The section name to look up.

Returns

IniSection

The matching IniSection, or null when not found.

Exceptions

ArgumentNullException

Thrown when name is null.

RemoveSectionCore(string)

Removes the section with the supplied name. When multiple sections share the same name (under Preserve or MergeAdjacent ), every occurrence is removed. Intended for use by derived types that expose a mutation surface.

protected bool RemoveSectionCore(string name)

Parameters

name string

The section name to remove.

Returns

bool

true when at least one section was removed; otherwise, false.

Exceptions

ArgumentNullException

name is null.

TryGetSection(string, out IniSection?)

Gets the named section with the specified name.

public bool TryGetSection(string name, out IniSection? section)

Parameters

name string

The section name to look up.

section IniSection

When this method returns true, contains the matching section; otherwise, null.

Returns

bool

true when the section is present; otherwise, false.

Exceptions

ArgumentNullException

Thrown when name is null.

Applies to

ProductVersions
.NET8, 10