我有一本动态字典。
public Dictionary<int, dynamic> Data = new Dictionary<int, dynamic>();
动态部分将包含仅由 5-6 个获取/设置属性组成的简单类,例如类的外观。
public class Class1
{
public int Property1 { get; set; }
public int Property2 { get; set; }
}
和
public class Class2
{
public string Property1 { get; set; }
public string Property2 { get; set; }
}
我尝试将这 2 个类添加到我的字典中,然后序列化字典但收到错误。只是想知道 Protobuf.Net 是否能够序列化和反序列化这样的字典?如果是这样,这是如何实现的?
最佳答案
简短的回答是“不是真的”。可能有一些方法可以让它发挥作用,但我不推荐它 - 它很难维护。
protobuf-net(和一般的 protobuf)在序列化器提前知道结构时效果最好。
关于c# - Protobuf.Net 可以序列化动态字典吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15741797/