Tomlyn is a TOML parser, validator and authoring library for .NET Framework and .NET Core
- Very fast parser, GC friendly.
- Compatible with the latest TOML 1.0.0 specs.
- Support perfect load/save roundtrip while preserving all spaces, new line, comments.
- Provides a validator with the
Toml.Validate
method. - Provides accurate parsing and validation error messages with precise source location.
- Allow to work on the syntax tree directly (preserving styles) through the
Toml.Parse
. - Allow to work with a runtime representation
Toml.ToModel
andToml.ToModel<T>
(but cannot be saved back to TOML). - Supports for .NET Standard 2.0+.
var input = @"[mytable]
key = 15
val = true
";
// Gets a syntax tree of the TOML text
var doc = Toml.Parse(input); // returns a DocumentSyntax
// Check for parsing errors with doc.HasErrors and doc.Diagnostics
// doc.HasErrors => throws an exception
// Prints the exact representation of the input
var docStr = doc.ToString();
Console.WriteLine(docStr);
// Gets a runtime representation of the syntax tree
var table = doc.ToModel();
var key = (long) ((TomlTable) table["mytable"])["key"];
var value = (bool) ((TomlTable) table["mytable"])["val"];
Console.WriteLine($"key = {key}, val = {value}");
Creates a TOML document programmatically:
var doc = new DocumentSyntax()
{
Tables =
{
new TableSyntax("test")
{
Items =
{
{"a", 1},
{"b", true },
{"c", "Check"},
{"d", "ToEscape\nWithAnotherChar\t" },
{"e", 12.5 },
{"f", new int[] {1,2,3,4} },
{"g", new string[] {"0", "1", "2"} },
{"key with space", 2}
}
}
}
};
Console.WriteLine(doc);
// Prints:
// [test]
// a = 1
// b = true
// c = "Check"
// d = "ToEscape\nWithAnotherChar\t"
// e = 12.5
// f = [1, 2, 3, 4]
// g = ["0", "1", "2"]
// "key with space" = 2
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.