c# - Skip elements during deserialization with BinaryFormatter -
is there possibility skip next 'entry' of serialized stream when deserializing? regarding plugin-oriented architecture can happen distinct parts of serialized object graphs might become unknown types in environment (assume safely ignored). trying deserialize these of course fail.
abstract class thing{} class onething : thing {} // <-- known in environment & b class : thing {} // <-- known in environment ... var things = new list<thing>(); ... things.add( (onething)(formatter.deserialize(stream)) ); things.add( (something)(formatter.deserialize(stream)) ); // <-- skip in b things.add( (onething)(formatter.deserialize(stream)) ); how working binary formatter? have calculate length , retrieve unambigous type-name (e.g. string) of serialized entry , store right before entry itself, can skip on when deserializing (by incrementing stream pointer)? or there better alternative less problem specific manipulation of serialized representation?
binaryformatter type-based serializer. frankly, if types aren't known (and known identical, including assembly/identity), bad idea use binaryformatter in first place. serializers choke if can't understand data, without offering great "skip" options. know protobuf-net does allow simple recovery type of scenario, protobuf-net wants know subtypes in advance, doesn't make hugely applicable plugin scenarios.
Comments
Post a Comment