Can protobuf-net serialize this combination of interface and shared collection?

I am trying to serialize ItemTransaction, and protobuf-net (r282) has a problem.

ItemTransaction : IEnumerable<KeyValuePair<Type, IItemCollection>></code>

and ItemCollection:

FooCollection : ItemCollection<Foo>
ItemCollection<T> : BindingList<T>, IItemCollection
IItemCollection : IList<Item>

where T is the derived type of Item. ItemCollection also has a property of type IItemCollection.

I serialize as follows:

IItemCollection itemCol = someService.Blah(...);
...
SerializeWithLengthPrefix<IItemCollection>(stream, itemCol, PrefixStyle.Base128);

My ultimate goal is to serialize ItemTransaction, but I got hooked on IItemCollection.

An element and its derived types can be [de] serialized without problems, see [1], but the deserialization of the failures is IItemCollection (serialization works). ItemCollection has the ItemExpression property and cannot descript an abstract class when deserializing a protobuff. It makes sense to me, but I'm not sure how to get through this.

ItemExpression<T> : ItemExpression, IItemExpression
ItemExpression : Expression

ItemExpression is abstract as an expression

How can I make this work correctly?

, , ItemTransaction , IItemCollections (ItemTransaction FooCollection, BarCollection, FlimCollection, FlamCollection ..).

()?

[1] protobuf-net [de]

+3
1

; Merge ( , protobuf-net ).

ItemExpression [ProtoInclude(...)] ItemExpression<T>, - , ! . , .

, , .


, , , , :

  • Deserialize..., IList<T> List<T>; , Merge , .
  • Item, Foo, Bar Item Foo Item Bar
  • "v2" ( ) ( ).
  • , , , . "v2" , (, , "WithLengthPrefix" /list outermost methods, )
  • "v2" , , ( , - )

; . .

+1

Source: https://habr.com/ru/post/1741835/


All Articles