Table of Contents

ConfigurationParseOptions Class

Definition

Namespace
Bodu.Text.Configuration
Assembly
Bodu.Text.Configuration.dll
Package
Bodu.Text.Configuration 1.0.0
Source
ConfigurationParseOptions.Presets.cs

Controls how a configuration document is parsed: comment handling, duplicate handling, diagnostic routing, length limits, and the key mapping options.

public sealed class ConfigurationParseOptions
Inheritance
ConfigurationParseOptions
Inherited Members
Extension Methods

Remarks

The options bag is a profile-grouped set of init-only properties. Start from a named preset that matches the hosting flavour - Bodu for the default Bodu Text Configuration semantics, EditorConfigCompatible for strict EditorConfig parity, Strict for fail-fast behaviour, or Relaxed for lenient parsing - and override the specific properties that need to differ. Use For(ConfigurationProfile) when the profile is data-driven (for example, read from configuration).

DiagnosticMode is the most consequential knob. In Throw the reader raises ConfigurationParseException on the first recoverable error; in Collect the parser drives through the document and reports every recoverable issue via the parse result's Diagnostics list. Pair the latter with ParseWithDiagnostics(string, ConfigurationParseOptions?).

Key shape is delegated to KeyOptions. Sharing one configured ConfigurationKeyOptions instance between parse and ConfigurationResolveOptions keeps the parsed model and the resolved view's lookups consistent. Instances are safe to cache and share across threads because every property is init-only.

// Strict structure, but collect every diagnostic instead of failing fast.
var options = new ConfigurationParseOptions
{
    Profile        = ConfigurationProfile.Strict,
    DiagnosticMode = ConfigurationDiagnosticMode.Collect,
};

ConfigurationParseResult result = ConfigurationDocument.ParseWithDiagnostics(text, options);
foreach (ConfigurationDiagnostic d in result.Diagnostics)
    Console.WriteLine(d);

Constructors

ConfigurationParseOptions()

public ConfigurationParseOptions()

Properties

AllowKeyOnlyProperties

Gets a value indicating whether key-only properties (lines with no =) are permitted.

public bool AllowKeyOnlyProperties { get; init; }

Property Value

bool

true when key-only lines are permitted; otherwise, false. The default is false.

Bodu

Gets the canonical option set for the default Bodu profile: WhitespaceIntroduced inline comments, LastWins duplicates, Preserve sections, and throw-on-error diagnostics.

public static ConfigurationParseOptions Bodu { get; }

Property Value

ConfigurationParseOptions

A cached default options instance.

DefaultEncoding

Gets the encoding to assume when loading a configuration document from a byte stream without a byte order mark. The default is UTF8.

public Encoding DefaultEncoding { get; init; }

Property Value

Encoding

The default encoding.

DiagnosticMode

Gets the diagnostic routing mode that controls whether recoverable errors throw, are collected on the document, or are silently ignored.

public ConfigurationDiagnosticMode DiagnosticMode { get; init; }

Property Value

ConfigurationDiagnosticMode

The selected diagnostic mode.

DuplicateKeyMode

Gets the duplicate key handling mode used by the reader.

public DuplicateKeyPolicy DuplicateKeyMode { get; init; }

Property Value

DuplicateKeyPolicy

The selected duplicate key mode.

DuplicateSectionMode

Gets the duplicate section handling mode used by the reader.

public IniDuplicateSectionBehavior DuplicateSectionMode { get; init; }

Property Value

IniDuplicateSectionBehavior

The selected duplicate section mode.

EditorConfigCompatible

Gets the canonical option set for the EditorConfig-compatible profile: inline comments disabled, duplicates last-wins, preserve duplicate sections, and throw-on-error diagnostics.

public static ConfigurationParseOptions EditorConfigCompatible { get; }

Property Value

ConfigurationParseOptions

A cached EditorConfig-compatible options instance.

InlineCommentMode

Gets the inline comment handling mode used by the reader.

public ConfigurationInlineCommentMode InlineCommentMode { get; init; }

Property Value

ConfigurationInlineCommentMode

The selected inline comment mode.

KeyOptions

Gets the key options used to split raw keys into segments and map them to the configuration key shape.

public ConfigurationKeyOptions KeyOptions { get; init; }

Property Value

ConfigurationKeyOptions

The selected key options.

MaxKeyLength

Gets the maximum permitted length of an individual key, in characters.

public int MaxKeyLength { get; init; }

Property Value

int

A positive key-length cap.

MaxLineLength

Gets the maximum permitted length of an individual line, in characters.

public int MaxLineLength { get; init; }

Property Value

int

A positive line-length cap.

Profile

Gets the behaviour profile this option bag represents. The default is Bodu.

public ConfigurationProfile Profile { get; init; }

Property Value

ConfigurationProfile

The selected profile.

Relaxed

Gets the canonical option set for permissive parsing of user-authored files: inline comments enabled, duplicates last-wins, preserve duplicate sections, and collect-on-error diagnostics.

public static ConfigurationParseOptions Relaxed { get; }

Property Value

ConfigurationParseOptions

A cached relaxed options instance.

SectionHeaderMode

Gets the section-header trailing-content handling mode used by the reader. The default, Lenient, accepts trailing words silently and matches the historical Bodu profile; the EditorConfig-compatible and strict presets use Strict instead.

public ConfigurationSectionHeaderMode SectionHeaderMode { get; init; }

Property Value

ConfigurationSectionHeaderMode

The selected section-header mode.

Strict

Gets the canonical option set for strict, deterministic parsing intended for generated files: inline comments disabled, duplicate keys rejected, duplicate sections rejected, throw-on-error.

public static ConfigurationParseOptions Strict { get; }

Property Value

ConfigurationParseOptions

A cached strict options instance.

TrimKeysAndValues

Gets a value indicating whether keys and values should be trimmed of leading and trailing whitespace.

public bool TrimKeysAndValues { get; init; }

Property Value

bool

true when the parser trims; otherwise, false. The default is true, matching EditorConfig.

Methods

For(ConfigurationProfile)

Returns the canonical option set for the specified profile.

public static ConfigurationParseOptions For(ConfigurationProfile profile)

Parameters

profile ConfigurationProfile

The profile to materialize.

Returns

ConfigurationParseOptions

An options instance configured for profile.

Exceptions

ArgumentOutOfRangeException

profile is not a defined value.

Applies to

ProductVersions
.NET8, 10