MetaMessage 0.1.0
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 MetaMessage --version 0.1.0
NuGet\Install-Package MetaMessage -Version 0.1.0
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="MetaMessage" Version="0.1.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="MetaMessage" Version="0.1.0" />
<PackageReference Include="MetaMessage" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add MetaMessage --version 0.1.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: MetaMessage, 0.1.0"
#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.
#:package MetaMessage@0.1.0
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=MetaMessage&version=0.1.0
#tool nuget:?package=MetaMessage&version=0.1.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
MetaMessage
MetaMessage 的 C# 实现,提供高性能的二进制序列化、JSONC 解析和对象绑定功能。
1. 安装
1.1 项目引用
将 MetaMessage 添加到您的项目中:
# 使用 .NET CLI
dotnet add reference ../../mm-cs/src/MetaMessage/MetaMessage.csproj
1.2 版本要求
- .NET 8.0 或更高版本
2. API 使用
2.1 JSONC 解析与输出
using MetaMessage.Jsonc;
using JsoncParser = MetaMessage.Jsonc.Jsonc;
string jsonc = @"{
// mm: type=str; desc=姓名
""name"": ""Alice"",
// mm: type=i; desc=年龄; min=0; max=150
""age"": 25,
// mm: type=bool; desc=是否激活
""active"": true,
// mm: type=array; child_type=i; desc=分数
""scores"": [95, 87, 92]
}";
// 解析 JSONC 到节点树
var node = JsoncParser.ParseFromString(jsonc);
// 格式化输出
Console.WriteLine(JsoncParser.ToString(node));
// 紧凑输出
Console.WriteLine(JsoncParser.ToMinString(node));
// 从字节数组解析
byte[] bytes = Encoding.UTF8.GetBytes(jsonc);
var nodeFromBytes = JsoncParser.ParseFromBytes(bytes);
2.2 JSONC 绑定到对象
public class User
{
public string name { get; set; } = "";
public int age { get; set; }
public bool active { get; set; }
public List<int> scores { get; set; } = new();
}
// 绑定 JSONC 到强类型对象
var user = JsoncParser.BindFromString<User>(jsonc);
Console.WriteLine($"name: {user.name}, age: {user.age}");
// 绑定到已有对象
var target = new User();
JsoncParser.BindFromString(jsonc, target);
2.3 对象转 JSONC
var user = new User
{
name = "Bob",
age = 28,
active = true,
scores = new List<int> { 100, 90, 80 }
};
string output = JsoncParser.ValueToNodeString(user);
Console.WriteLine(output);
2.4 JSONC 值提取
object? extracted = JsoncParser.ExtractValue(node);
// 返回纯 JSON 对象(字典、列表、原始值)
3. 完整示例
查看 examples/csharp/ 目录下的完整运行示例:
cd examples/csharp
dotnet run
示例包含以下功能:
- JSONC 解析与格式化输出
- JSONC 绑定到强类型对象
- 对象转 JSONC
- JSONC 值提取
- 从字节数组解析 JSONC
4. 测试方法
cd mm-cs
dotnet test
测试框架:xUnit + .NET Test SDK
5. 相关资源
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. 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. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net8.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.