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
globalSectionIniSectionThe global section (entries authored before the first named section header). Its Name must be the empty string.
sectionsIEnumerable<IniSection>The ordered, named sections that follow the global section.
caseSensitiveSectionsbooltrue to compare section names with ordinal case sensitivity; otherwise, false (the INI default).
Exceptions
- ArgumentNullException
Thrown when
globalSectionorsectionsis null.- ArgumentException
Thrown when
globalSectionhas a non-empty Name, or whensectionscontains 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
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
sectionIniSectionThe section to append.
Exceptions
- ArgumentNullException
sectionis null.- ArgumentException
sectionhas 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
namestringThe section name.
Returns
- IniSection
The matching or newly created section.
Exceptions
- ArgumentNullException
nameis null.- ArgumentException
nameis empty.
GetSection(string)
Gets the named section with the specified name, or null if it is absent.
public IniSection? GetSection(string name)
Parameters
namestringThe section name to look up.
Returns
- IniSection
The matching IniSection, or null when not found.
Exceptions
- ArgumentNullException
Thrown when
nameis 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
namestringThe section name to remove.
Returns
Exceptions
- ArgumentNullException
nameis null.
TryGetSection(string, out IniSection?)
Gets the named section with the specified name.
public bool TryGetSection(string name, out IniSection? section)
Parameters
namestringThe section name to look up.
sectionIniSectionWhen this method returns true, contains the matching section; otherwise, null.
Returns
Exceptions
- ArgumentNullException
Thrown when
nameis null.
Applies to
| Product | Versions |
|---|---|
| .NET | 8, 10 |