Reputation: 1277
I have a HybridDictionary
object. Is it possible to use Protobuf-net
to serialize HybridDictionary
object?
Upvotes: 1
Views: 37
Reputation: 1062975
Not presently, and for good reasons:
HybridDictionary
, since it only advertises object
for both the key and value; protobuf-net really, really wants to understand the types involvedstring
), but often of the valueAs such, I would strongly recommend using Dictionary<TKey, TValue>
or something that implements IDictionary<TKey, TValue>
. In theory we could add APIs allowing you to tell it how to interpret the key and value (and obviously do the work to support that in the library), but I'm dubious as to whether that would actually be of real benefit. Frankly, I'm not sure that there is much purpose in using HybridDictionary
these days (or for the last many years).
Actually, until 2.3.0, protobuf-net didn't really support Dictionary<TKey, TValue>
directly - at least, not in the way you might think: until the map<...,...>
feature was fully implemented, what it actually saw was a list-like-thing, i.e. something that could be interpreted as a sequence of {some type}
, with an Add({some type})
method. In the case of dictionary, the {some type}
happens to be KeyValuePair<TKey, TValue>
, which in turn can be interpreted as a tuple-like type (with members that exactly match the constructor, so infer the contract based on the constructor arguments). Conveniently, this turns out to be the exact same shape that map<...,...>
uses, so this approach is interchangeable (data-wise) with the new approach preferred in 2.3.0 (which is discussed more here).
Upvotes: 1