HKWToml 1.0.5
Suggested Alternatives
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package HKWToml --version 1.0.5
NuGet\Install-Package HKWToml -Version 1.0.5
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.0.5" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add HKWToml --version 1.0.5
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: HKWToml, 1.0.5"
#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.0.5 // Install HKWToml as a Cake Tool #tool nuget:?package=HKWToml&version=1.0.5
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
HKWToml
GitHub
HKWToml 是使用 C# 编写的
包含有 TOML 的读取和编写,序列化反序列化, TOML 转换为 C# 类功能
其中 读取器和编写器 修改至Tommy
可以添加单独的 TomlParse.cs 文件以只使用读取器和编写器功能
或者从NuGet包中获取完整功能
特征
- 完全实现 TOML1.0.0 规范
- 对解析和保存注释的基本支持
- 支持.NET 3.5+,Mono,.NET Core!
如何使用
TOML 文件
# This is a TOML document
# title
# tttttttttttttttt
title = "TOML Example"
# int1
int1 = 123456789
# long1
long1 = 1234567890000
# noop
noop = [{ a = 1, b = 2 }, { b = 2, c = 3 }]
[owner]
# name
name = "Tom Preston-Werner"
date = 2022-07-23
dob = 1979-05-27T07:32:00-08:00
[database]
enabled = true
points = [[1, 2, 3], [4, 5.5, 6], [7, 8, 99999999999999]]
ports = [8000, 8001, 8002]
data = [["delta", "phi"], [3.14]]
temp_targets = { cpu = 79.5, apu = 72.0 }
[servers]
# aaa
[servers.alpha]
ip = "10.0.0.1"
role = "frontend"
# bbb
[servers.beta]
ip = "10.0.0.2"
role = "backend"
解析 Toml 文件
using HKW.TOML
string file = "test.toml";
// 从文件中读取
TomlTable table = TOML.Parse(file);
// 从流中读取
// using(StreamReader reader = File.OpenText("configuration.toml"))
// {
// TomlTable table = TOML.Parse(reader);
// }
// 获取数据
Console.WriteLine(table["title"]);
Console.WriteLine(table["owner"]["name"]);
// 获取注释
Console.WriteLine(table.Comment);
// 遍历所有数据
foreach(var keyValue in table)
Console.WriteLine($"Name = {keyValue.Key}, Value = {keyValue.Value}");
创建 TomlTable
using HKW.TOML
string file = "test.toml";
TomlTable toml = new TomlTable
{
["title"] = "TOML Example",
// You can also insert comments before a node with a special property
["value-with-comment"] = new TomlString
{
Value = "Some value",
Comment = "This is just some value with a comment"
},
// You don't need to specify a type for tables or arrays -- Tommy will figure that out for you
["owner"] =
{
["name"] = "Tom Preston-Werner",
["dob"] = DateTime.Now
},
["array-table"] = new TomlArray
{
// This is marks the array as a TOML array table
IsTableArray = true,
[0] =
{
["value"] = 10
},
[1] =
{
["value"] = 20
}
},
["inline-table"] = new TomlTable
{
IsInline = true,
["foo"] = "bar",
["bar"] = "baz",
// Implicit cast from TomlNode[] to TomlArray
["array"] = new TomlNode[] { 1, 2, 3 }
}
};
toml.SaveTo(file);
从 TOML 文件 生成 C# 的类
生成相关设置请查看TomlAsClassesOptions
using HKW.TOML
string file = "test.toml";
string classString = TomlAsClasses.ConstructFromFile(file, "Test");
Console.WriteLine(classString);
TOML 反序列化
反序列化相关设置请查看TomlDeserializerOptions
using HKW.TOML
string file = "test.toml";
Test test = TomlDeserializer.DeserializeFromFile<Test>(file);
TOML 序列化
序列化相关设置请查看TomlSerializerOptions
using HKW.TOML
string newFile = "newTest.toml";
TomlSerializer.SerializeToFile(test, newFile);
Product | Versions 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 was computed. 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.
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 | 271 | 4/26/2023 | |
1.1.5 | 204 | 4/25/2023 | |
1.1.4 | 206 | 4/25/2023 | |
1.1.3 | 207 | 4/25/2023 | |
1.1.2 | 198 | 4/24/2023 | |
1.1.1 | 196 | 4/24/2023 | |
1.1.0 | 207 | 4/18/2023 | |
1.0.10 | 241 | 4/7/2023 | |
1.0.9 | 215 | 4/6/2023 | |
1.0.8 | 211 | 4/6/2023 | |
1.0.7 | 241 | 4/6/2023 | |
1.0.6 | 240 | 4/6/2023 | |
1.0.5 | 237 | 4/6/2023 | |
1.0.4 | 230 | 4/6/2023 | |
1.0.3 | 233 | 4/5/2023 | |
1.0.2 | 218 | 4/4/2023 | |
1.0.1 | 214 | 4/4/2023 | |
1.0.0 | 237 | 4/4/2023 |