Bodu.Text.Toml
1.3.0
dotnet add package Bodu.Text.Toml --version 1.3.0
NuGet\Install-Package Bodu.Text.Toml -Version 1.3.0
<PackageReference Include="Bodu.Text.Toml" Version="1.3.0" />
<PackageVersion Include="Bodu.Text.Toml" Version="1.3.0" />
<PackageReference Include="Bodu.Text.Toml" />
paket add Bodu.Text.Toml --version 1.3.0
#r "nuget: Bodu.Text.Toml, 1.3.0"
#:package Bodu.Text.Toml@1.3.0
#addin nuget:?package=Bodu.Text.Toml&version=1.3.0
#tool nuget:?package=Bodu.Text.Toml&version=1.3.0
Bodu.Text.Toml
API stability - Stable. The public API surface is committed: breaking changes are reserved for a major-version bump per SemVer, except a deliberate break that is recorded in the release notes and in the package's
CompatibilitySuppressions.xml. See versioning and support.
A TOML (v1.0.0 / v1.1.0) library for .NET 8 and .NET 10. It maps plain CLR objects to and from TOML through a configurable converter model, over a low-level forward-only token reader and writer, with both a mutable and a read-only document object model.
Installation
dotnet add package Bodu.Text.Toml
Targets net8.0 and net10.0.
API shape
The public surface follows the same System.Text.Json-shaped architecture as the sibling Bodu.Text.Bencode and Bodu.Text.Yaml libraries, so the patterns transfer directly between them; the options differ where the formats do (for example, PropertyNameCaseInsensitive defaults to false here and to true in Bencode). The types are organised into folders/namespaces by surface:
| Type(s) | Namespace | Role |
|---|---|---|
TomlSerializer / TomlSerializerOptions / TomlSerializerDefaults |
Bodu.Text.Toml |
Static serializer entry point, its configuration, and scenario presets (for example Web). |
TomlTokenType, TomlValueKind |
Bodu.Text.Toml |
Token classification and value-kind classification (naming policies are the shared Bodu.Text.Serialization.NamingPolicy). |
TomlFormatException / TomlSerializationException |
Bodu.Text.Toml |
Failures split by cause: malformed input vs. values that cannot be mapped. |
Utf8TomlReader (+ TomlReaderOptions) |
Bodu.Text.Toml.Reader |
Forward-only, allocation-free ref struct token reader. |
Utf8TomlWriter (+ TomlWriterOptions) |
Bodu.Text.Toml.Writer |
Forward-only ref struct token writer. |
TomlDocument / TomlElement / TomlProperty |
Bodu.Text.Toml.Document |
Read-only, low-allocation document object model. |
TomlNode / TomlObject / TomlArray / TomlValue |
Bodu.Text.Toml.Nodes |
Mutable document object model: parse, edit, write back. |
TomlConverter<T> / TomlConverterFactory, TomlStringEnumConverter (+ generic) / TomlNumberEnumConverter<TEnum> |
Bodu.Text.Toml.Serialization |
Custom converters, converter factories, and the public enum converters; the per-member attribute family is the shared Bodu.Text.Serialization set ([PropertyName] / [Ignore] / [Converter] / …). |
using Bodu.Text.Toml;
string toml = TomlSerializer.Serialize(new ServerConfig { Host = "localhost", Port = 8080 });
ServerConfig config = TomlSerializer.Deserialize<ServerConfig>(toml);
// Document object models
using Bodu.Text.Toml.Nodes;
TomlNode node = TomlNode.Parse(utf8Toml)!;
node["server"]!["port"] = 9090;
byte[] back = node.ToUtf8Bytes();
- Value mapping:
string/char/Guid/Uri→ string, the integer family → integer,double/float→ float,bool→ boolean, andDateTimeOffset/DateTime/DateOnly/TimeOnly→ the four RFC 3339 date-time forms;byte[]→ an integer array (or a Base64 string viaTomlSerializerOptions.ByteArrayHandling); enums → member-name strings.decimalmaps to a float or, for full precision, a string (TomlSerializerOptions.DecimalHandling), andTimeSpanto its invariant"c"-format string. - A TOML document root must map to a table, so a top-level scalar or array throws. Output is normalized TOML in document order - deterministic for a given input, with member order preserved (so
[PropertyOrder]is honored). It is not a canonical form: two equal documents built in different member orders serialize differently, so the output is unsuitable for hashing or signing. - The full serializer feature surface is present: converters and factories, the shared attribute family (
PropertyName/Ignore/Converter/PropertyOrder/Constructor/Required/Include/ExtensionData/NamingPolicy/UnmappedMemberHandling/ObjectCreationHandling/StringEnumMemberName), the serialization callbacks (IOnSerializing/IOnSerialized/IOnDeserializing/IOnDeserialized), naming policies andTomlSerializerDefaults.Web, and the string/number enum converters. - Because the reader/writer/document types live in sub-namespaces, code that uses them alongside the serializer imports
using Bodu.Text.Toml.Reader;/.Writer;/.Document;/.Nodes;as needed. - Failures surface through
TomlFormatException(malformed input, with line/column/offset) andTomlSerializationException(binding failures).
Runnable samples
The repository ships offline, dotnet run-able sample projects for this package - the
TomlSerializer POCO surface (temporal kinds, naming policies and attributes, the wire
knobs) and the layers beneath it (both DOMs, the token reader/writer, streaming reads) -
under samples/Text.Toml/.
Building and testing
To build this package from source and run its tests, see CONTRIBUTING.md.
License
MIT. © Bodu Pty. Ltd.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- Bodu.Core (>= 1.3.0)
- Bodu.Text.Serialization (>= 1.3.0)
-
net8.0
- Bodu.Core (>= 1.3.0)
- Bodu.Text.Serialization (>= 1.3.0)
NuGet packages (3)
Showing the top 3 NuGet packages that depend on Bodu.Text.Toml:
| Package | Downloads |
|---|---|
|
Bodu.Globalization.Calendar.Caching
Caching layer for Bodu.Globalization.Calendar. Provides CachingNotableDateService, a decorator that wraps any INotableDateService and serves computed notable dates from a per-territory, per-civil-year cache (in-memory or one TOML/JSON file per territory), recording when each year was computed and refreshing on a configurable time-to-live or a resource-version change. Includes the dependency-injection registration (AddCachedNotableDateService) on IServiceCollection. |
|
|
Bodu.Financial.ExchangeRates.Caching
Caching layer for Bodu.Financial exchange-rate providers. Provides CachingRateProvider, a decorator that wraps any IDatedRateProvider and serves fresh rates from a shared on-disk cache (one TOML file per provider and currency pair), plus an AggregatingRateProvider (priority-fallback, averaging, per-pair routing). Includes the dependency-injection registrations (AddCachedRateProvider, AddAggregatedRateProvider) on IFinancialServiceBuilder. |
|
|
Bodu.Extensions.Configuration.Text
The EditorConfig-compatible Microsoft.Extensions.Configuration provider. Bridges Bodu.Text.Configuration into the standard IConfiguration / IOptions<T> pipeline so a .boduconfig or bodu.config file registers with the same AddTextConfiguration(...) shape used for the JSON, INI, and XML providers - with file, stream, and programmatic-document overloads, reload-on-change, and colon-delimited section binding. Also ships the read-only TOML (AddTomlFile / AddTomlStream) and Bencode (AddBencodeFile / AddBencodeStream) sources. |
GitHub repositories
This package is not used by any popular GitHub repositories.