我有一个相当重量级的 DTO 库,目前一些 WCF 服务正在使用它。我们正试图将它带入 protobuf-net 世界,尽可能少地进行修改。一组特定的项目给我序列化带来了麻烦。我将在这里简单地介绍它们,因为它有点复杂,但问题的要点是:
public class Key
{
public string Id {get; set;}
}
public class KeyCollection : IEnumerable<Key>
{
private readonly List<Key> list;
#region IEnumerable
// etc...
#endregion
}
public class Item
{
public long Id { get; set; }
}
public abstract class ContainerBase
{ }
public abstract class ContainerBase<T> : ContainerBase
where T : Item
{ }
public abstract class ContainerType1Base : ContainerBase<Item>
{
public KeyCollection Keys { get; set; }
}
public class ContainerType1 : ContainerType1Base
{ }
我忽略了装饰器,因为我不认为它们是问题,主要是因为如果我添加void Add(Key item) { }
到KeyCollection
整个东西似乎工作。否则,我在尝试序列化ContainerType1
.
实际上,更改的签名KeyCollection
有点令人望而却步,所以我试图按照这个答案尝试以编程方式进行。具体来说,在和的“键”上设置itemType
和defaultType
为空。我也设置为...这完全行不通。我在客户端上收到一个通用的“无法反序列化”异常,如果有帮助,我可以在这里发布。在服务器端,我使用 将其序列化,并吐出对象的 JSON 以及它们似乎都可以正常工作。ValueMember
ContainerType1
ContainerType1Base
ContainerBase<Item>
IgnoreListHandling
true
KeyCollection
Serializer.Serialize()
Serializer.GetProto<>()
如何关闭列表处理?与此相关,有没有办法在序列化时打开额外的调试以尝试获取有关问题的更多信息?