Tomlyn is a TOML parser, validator and authoring library for .NET Framework and .NET Core.
A config file format for humans. TOML aims to be a minimal configuration file format that's easy to read due to obvious semantics. TOML is designed to map unambiguously to a hash table. TOML should be easy to parse into data structures in a wide variety of languages.
Toml.ToModel(string)
Toml.ToModel<T>(string)
string Toml.FromModel(object)
ITomlMetadataProvider
.DocumentSyntax
via Toml.Parse(string)
.
Toml.Validate
method.See the documentation for more details.
Tomlyn is delivered as a NuGet Package.
var toml = @"global = ""this is a string""
# This is a comment of a table
[my_table]
key = 1 # Comment a key
value = true
list = [4, 5, 6]
";
// Parse the TOML string to the default runtime model `TomlTable`
var model = Toml.ToModel(toml);
// Fetch the string
var global = (string)model["global"]!;
// Prints: found global = "this is a string"
Console.WriteLine($"found global = \"{global}\"");
// Generates a TOML string from the model
var tomlOut = Toml.FromModel(model);
// Output the generated TOML
Console.WriteLine(tomlOut);
This will print the original TOML by preserving most the comments:
global = "this is a string"
# This is a comment of a table
[my_table]
key = 1 # Comment a key
value = true
list = [4, 5, 6]
NOTICE: By default, when mapping to a custom model, Tomlyn is using the PascalToSnakeCase naming convention (e.g
ThisIsFine
tothis_is_fine
). This behavior can be changed by overriding theTomlModelOptions.ConvertPropertyName
delegate.
This software is released under the BSD-Clause 2 license.
Modified version of the logo Thor
by Mike Rowe from the Noun Project (Creative Commons)
Alexandre Mutel aka xoofx.