Skip to content

HKW.TOML is TOML reader, writer, deserializer, serializer and generate classes for C#.

Notifications You must be signed in to change notification settings

Hakoyu/HKW.TOML

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

HKW.TOML

GitHub
HKW.TOML 是使用 C# 编写的
包含有 TOML 的读取和编写, 序列化反序列化, 生成 C# 实体类等功能
其中 读取器和编写器 修改至Tommy
可以添加单独的 TomlParse.cs 文件以只使用读取器和编写器功能
或者从NuGet包中获取完整功能

特征

  • 完全实现 TOML 1.0.0 规范
  • 对解析和保存注释的基本支持
  • 支持.NET 6+ !

如何使用

测试文件
测试 Toml 数据
测试类

TomlTable table = TOML.Parse(TomlExample.ExampleData);
//TomlTable table = TOML.ParseFromFile(TomlExample.ExampleFile);

string title = table["title"].AsString;
string titleComment = table["title"].Comment;
List<int> numbers = table["integers"].AsList.Select(node => node.AsInt32).ToList();

创建 TomlTable

TomlTable table =
    new()
    {
        new TomlString("TOML example \\U0001F60A")
        {
            Comment = "Simple key/value with a string."
        },
        new TomlArray() { 42, 0x42, 042, 0b0110 }
    };

生成相关设置请查看TomlAsClassesOptions

TomlTable table = TOML.Parse(TomlExample.ExampleData);
string classString = TomlAsClasses.Generate(table, "ClassExample");
Console.WriteLine(classString);

反序列化相关设置请查看TomlDeserializerOptions

TomlTable table = TOML.Parse(TomlExample.ExampleData);
ClassExample example = TomlDeserializer.Deserialize<ClassExample>(table);

序列化相关设置请查看TomlSerializerOptions

TomlTable table = TOML.Parse(TomlExample.ExampleData);
ClassExample example = TomlDeserializer.Deserialize<ClassExample>(table);
TomlTable serializeTable = TomlSerializer.Serialize(example);

About

HKW.TOML is TOML reader, writer, deserializer, serializer and generate classes for C#.

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages