HKWToml 1.1.6

Suggested Alternatives

HKW.TOML

dotnet add package HKWToml --version 1.1.6
NuGet\Install-Package HKWToml -Version 1.1.6
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="HKWToml" Version="1.1.6" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add HKWToml --version 1.1.6
#r "nuget: HKWToml, 1.1.6"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install HKWToml as a Cake Addin
#addin nuget:?package=HKWToml&version=1.1.6

// Install HKWToml as a Cake Tool
#tool nuget:?package=HKWToml&version=1.1.6

HKWToml

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

特征

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

如何使用

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

解析 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 }
    };

从 TOML 文件 生成 C# 的类

生成相关设置请查看TomlAsClassesOptions

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

TOML 反序列化

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

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

TOML 序列化

序列化相关设置请查看TomlSerializerOptions

TomlTable table = TOML.Parse(TomlExample.ExampleData);
ClassExample example = TomlDeserializer.Deserialize<ClassExample>(table);
TomlTable serializeTable = TomlSerializer.Serialize(example);
Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net6.0

    • No dependencies.
  • net7.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.1.6 236 4/26/2023
1.1.5 174 4/25/2023
1.1.4 172 4/25/2023
1.1.3 179 4/25/2023
1.1.2 165 4/24/2023
1.1.1 182 4/24/2023
1.1.0 178 4/18/2023
1.0.10 212 4/7/2023
1.0.9 184 4/6/2023
1.0.8 180 4/6/2023
1.0.7 211 4/6/2023
1.0.6 208 4/6/2023
1.0.5 208 4/6/2023
1.0.4 201 4/6/2023
1.0.3 208 4/5/2023
1.0.2 191 4/4/2023
1.0.1 185 4/4/2023
1.0.0 206 4/4/2023