如何序列化 dictionary<int, List<CustomeObject>> 使用 protobuf.net?

How to serialize dictionary<int, List<CustomeObject>> using protobuf.net?

我有一个复杂的对象,就像

Dictionary<ulong, List<MyObject>>

而 MyObject 派生自

List<A>

当我想序列化 Dictionary 时,它会抛出如下异常: [System.NotSupportedException] = {"Nested or jagged lists and arrays are not supported: System.Collections.Generic.List`1[[xxxx.MyObject, xxxx, Version=0.0.1.0, Culture=neutral, PublicKeyToken=null]]"}

如何解决? 我的 protobuf 版本是 2.3.2.0

这里的问题是物列表。这根本不受支持,因为它不能在底层协议 (protobuf) 中表达。

选项:

  • 切换到不是列表但列表的列表
  • 保留您现有的模型,但在您的自定义类型(子类列表的类型)上设置 "ignore list handling" 标志,并通过 属性
  • 公开列表内容