Table of Contents

TomlConfigurationExtensions Class

Definition

Namespace
Bodu.Extensions.Configuration.Text
Assembly
Bodu.Extensions.Configuration.Text.dll
Package
Bodu.Extensions.Configuration.Text 1.0.0
Source
TomlConfigurationExtensions.cs

Provides extension methods for adding a read-only TOML configuration source to an IConfigurationBuilder, mirroring the AddJsonFile / AddJsonStream shape.

public static class TomlConfigurationExtensions
Inheritance
TomlConfigurationExtensions
Inherited Members

Examples

builder.Configuration.AddTomlFile("appsettings.toml", optional: true);

using var stream = new MemoryStream(Encoding.UTF8.GetBytes("[logging]\nlevel = \"Debug\""));
builder.Configuration.AddTomlStream(stream);

Remarks

The resulting provider is read-once and read-only - it attaches no reload-on-change machinery and rejects mutation through IConfigurationProvider, because TomlConfigurationProvider exposes no mutation surface.

Methods

AddTomlFile(IConfigurationBuilder, string, bool)

Adds a read-only TOML configuration source backed by the file at path.

public static IConfigurationBuilder AddTomlFile(this IConfigurationBuilder builder, string path, bool optional = false)

Parameters

builder IConfigurationBuilder

The configuration builder.

path string

The TOML file path.

optional bool

When true, the file is permitted to be missing.

Returns

IConfigurationBuilder

The supplied builder, for chaining.

Exceptions

ArgumentNullException

Thrown when builder is null.

ArgumentException

Thrown when path is null, empty, or whitespace.

AddTomlStream(IConfigurationBuilder, Stream)

Adds a read-only TOML configuration source backed by the supplied Stream. The stream is read once when the configuration is built.

public static IConfigurationBuilder AddTomlStream(this IConfigurationBuilder builder, Stream stream)

Parameters

builder IConfigurationBuilder

The configuration builder.

stream Stream

The stream containing UTF-8 TOML text.

Returns

IConfigurationBuilder

The supplied builder, for chaining.

Exceptions

ArgumentNullException

Thrown when builder or stream is null.

Applies to

ProductVersions
.NET8, 10