【发布时间】:2010-04-19 20:47:06
【问题描述】:
我正在尝试序列化 ItemTransaction 并且 protobuf-net (r282) 有问题。
ItemTransaction : IEnumerable<KeyValuePair<Type, IItemCollection>></code>
ItemCollection 是这样的:
FooCollection : ItemCollection<Foo>
ItemCollection<T> : BindingList<T>, IItemCollection
IItemCollection : IList<Item>
其中 T 是 Item 的派生类型。 ItemCollection 还有一个 IItemCollection 类型的属性。
我是这样序列化的:
IItemCollection itemCol = someService.Blah(...);
...
SerializeWithLengthPrefix<IItemCollection>(stream, itemCol, PrefixStyle.Base128);
我的最终目标是序列化 ItemTransaction,但被 IItemCollection 困住了。
Item 及其派生类型可以毫无问题地 [de] 序列化,请参阅 [1],但反序列化 IItemCollection 失败(序列化工作)。 ItemCollection 具有 ItemExpression 属性,并且在反序列化 protobuf 时无法创建抽象类。这对我来说很有意义,但我不知道如何通过它。
ItemExpression<T> : ItemExpression, IItemExpression
ItemExpression : Expression
ItemExpression 和 Expression 一样是抽象的
如何让它正常工作?
另外,我担心 ItemTransaction 会失败,因为 IItemCollections 在编译时会有所不同且未知(ItemTransaction 将具有 FooCollection、BarCollection、FlimCollection、FlamCollection 等)。
我错过了什么(马克)?
【问题讨论】:
-
有关信息,已添加特定测试并通过“v2”;我没有碰过(缺少的)带长度前缀的代码,但是到了那里:code.google.com/p/protobuf-net/source/browse/trunk/…
标签: generics serialization protobuf-net