Introduction

edit

Meziantou.Framework.Toml reads and writes TOML documents in .NET. It maps documents to your own classes and records with an API shaped like System.Text.Json, reads them without a model as tables and arrays, and parses them into a syntax tree that keeps every character, for tools that edit TOML files.

What you can do with it

  • Serialize and deserialize objects: classes, records and structs, collections, dictionaries, dates and times, enums, with naming policies, attributes, custom converters and polymorphism. See Serialization.
  • Generate the serialization code at build time with the source generator that ships in the package, for NativeAOT, trimmed applications and errors reported when you build. See Source generation.
  • Read and build documents without a model with TomlTable, TomlArray and TomlTableArray, and keep the comments of a file you edit. See Document model.
  • Analyze or reformat TOML files with a lossless syntax tree, a lexer and an event parser. See Syntax tree, lexer and parser.

TOML versions

The library reads TOML 1.1, which accepts every TOML 1.0 document, and writes documents that TOML 1.0 readers can read too. See TOML 1.0 and 1.1.

Choose an API

You want toUse
Load a configuration file into your own types, or save themTomlSerializer with your types. See Getting started.
Do the same in a NativeAOT or trimmed applicationTomlSerializer with a TomlSerializerContext. See Source generation.
Read a document whose shape you don't know, or build one by codeTomlSerializer with TomlTable. See Document model.
Change a few values of a file and keep its commentsTomlTable with a TomlMetadataStore. See Document model.
Write a formatter, a linter or an editor featureSyntaxParser. See Syntax tree, lexer and parser.

Namespaces

NamespaceContains
Meziantou.Framework.TomlTomlSerializer, TomlSerializerOptions, TomlTypeInfo<T>, TomlDateTime, TomlException, the naming policies
Meziantou.Framework.Toml.SerializationThe attributes, TomlSerializerContext, the converters, TomlReader, TomlWriter, TomlMetadataStore
Meziantou.Framework.Toml.ModelThe document model: TomlTable, TomlArray, TomlTableArray
Meziantou.Framework.Toml.ParsingSyntaxParser, TomlLexer, TomlParser
Meziantou.Framework.Toml.SyntaxThe syntax tree: DocumentSyntax, KeyValueSyntax, SyntaxVisitor, the diagnostics

The serializer has its own attributes: the System.Text.Json.Serialization attributes, such as [JsonPropertyName], are not recognized.

Next steps