Giter Club home page Giter Club logo

tomlyn's Introduction

Tomlyn Build Status Coverage Status NuGet

Tomlyn is a TOML parser, validator and authoring library for .NET Framework and .NET Core.

What is TOML?

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.

Features

  • Very fast parser, GC friendly.
  • Compatible with the latest TOML v1.0.0 specs.
  • Allow to map a TOML string to a default runtime model via Toml.ToModel(string)
  • Allow to map a TOML string to a custom runtime model via Toml.ToModel<T>(string)
    • Very convenient for loading custom configurations for example.
  • Allow to generate a TOML string from a runtime model via string Toml.FromModel(object)
    • Preserve comments, by default with the default runtime model, or by implementing the ITomlMetadataProvider.
  • Allow to parse to a DocumentSyntax via Toml.Parse(string).
    • Preserve all spaces, new line, comments but also invalid characters/tokens.
    • Can roundtrip to text with exact representation.
  • Provides a validator with the Toml.Validate method.
  • Supports for .NET Standard 2.0+ and provides an API with nullable annotations.

Documentation

See the documentation for more details.

Usage

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 to this_is_fine). This behavior can be changed by overriding the TomlModelOptions.ConvertPropertyName delegate.

License

This software is released under the BSD-Clause 2 license.

Credits

Modified version of the logo Thor by Mike Rowe from the Noun Project (Creative Commons)

Author

Alexandre Mutel aka xoofx.

tomlyn's People

Contributors

xoofx avatar 0xced avatar tylerreid avatar sparkrai avatar alexmaris avatar jprogrammer avatar jeskew avatar mgnslndh avatar oconnor0 avatar nyctef avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.