ConfigurationParseOptions Class
Definition
- Namespace
- Bodu.Text.Configuration
- Assembly
- Bodu.Text.Configuration.dll
- Package
- Bodu.Text.Configuration 1.3.0
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 flavor - Bodu for the default Bodu Text Configuration semantics,
EditorConfigCompatible for EditorConfig alignment, Strict for fail-fast behavior, 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.
Profile only labels the option set. The individual properties carry the behavior, so start from a preset or For(ConfigurationProfile) to select a profile, and set every property that the variation needs.
// Strict structure, but collect every diagnostic instead of failing fast. The properties, not Profile, select the
// behaviour, so the variation states each of the Strict preset's choices.
var options = new ConfigurationParseOptions
{
Profile = ConfigurationProfile.Strict,
InlineCommentMode = ConfigurationInlineCommentMode.Disabled,
DuplicateKeyMode = DuplicateKeyPolicy.Disallowed,
DuplicateSectionMode = IniDuplicateSectionBehavior.Disallowed,
SectionHeaderMode = ConfigurationSectionHeaderMode.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
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, throw-on-error diagnostics, and the Identity key mapping with keys lowercased, so a key is kept as written, its dots and colons included, and reads as EditorConfig lowercases it.
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 profile this option set was created from. The default is Bodu.
public ConfigurationProfile Profile { get; init; }
Property Value
- ConfigurationProfile
The profile the option set is labeled with.
Remarks
The property is informational: the parser does not read it, and setting it changes no other property. Use For(ConfigurationProfile) or a preset to select a profile's behavior.
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
Methods
For(ConfigurationProfile)
Returns the canonical option set for the specified profile.
public static ConfigurationParseOptions For(ConfigurationProfile profile)
Parameters
profileConfigurationProfileThe profile to materialize.
Returns
- ConfigurationParseOptions
An options instance configured for
profile.
Exceptions
- ArgumentOutOfRangeException
profileis not a defined value.
Applies to
| Product | Versions |
|---|---|
| .NET | 8, 10 |