繁体   English   中英

c# MessagePack-CSharp 所有公共成员必须标记KeyAttribute 或IgnoreMemberAttribute。 我的类型成员:

[英]c# MessagePack-CSharp all public members must mark KeyAttribute or IgnoreMemberAttribute. MyType member:

使用 MessagePack-CSharp 时出现以下错误: c# MessagePack all public members must mark KeyAttribute or IgnoreMemberAttribute. MyTypmember:Id c# MessagePack all public members must mark KeyAttribute or IgnoreMemberAttribute. MyTypmember:Id

它抛出的错误很简单,因为我没有为某些成员添加密钥。 我没有这样做的原因是因为我的 class 继承自那些成员所属的第三方 dll,我无法用 Key 属性标记它们。 我当然可以覆盖它们,但这会很麻烦,因为我有几十个模型需要序列化并从第 3 方 dll 继承。有没有办法为第 3 方程序集指定这些属性,类似于 automapper 创建配置文件的方式

尝试尝试无类型序列化

object mc = new Sandbox.MyClass()
{
    Age = 10,
    FirstName = "hoge",
    LastName = "huga"
};

// Serialize with the typeless API
var blob = MessagePackSerializer.Typeless.Serialize(mc);

// Blob has embedded type-assembly information.
// ["Sandbox.MyClass, Sandbox",10,"hoge","huga"]
Console.WriteLine(MessagePackSerializer.ConvertToJson(bin));

// You can deserialize to MyClass again with the typeless API
// Note that no type has to be specified explicitly in the Deserialize call
// as type information is embedded in the binary blob
var objModel = MessagePackSerializer.Typeless.Deserialize(bin) as MyClass;

https://github.com/neuecc/MessagePack-CSharp#typeless

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM