c# - Protocol Buffers NET to serialize a SortedDictionary<CustomTKey, CustomTValue>? -


are there known issues when using protobuf.net sorteddictionary? specifically, we're using sorteddictionary<customtkey, customtvalue> (with appropriate icomparer<customtkey> implementation that's unrelated protobuf.net's focus)

it's passing basic tests @ our end wanted know if there known issues or concerns watch out for.

if works, working extend in general manner other types collection classes in bcl (eg: dictionary, sortedlist etc)? know sure works lists!

protobuf-net tries avoid coding specific collection types, , instead tries detect key patterns; in particular, looks ilist, icollection<t>, or custom iterator , add(foo), getenumerator() returns iterator .current of type foo.

sorteddictionary<tkey,tvalue> implements icollection<keyvaluepair<tkey, tvalue>>, protobuf-net detects , uses; library treats collection of key-value-pairs, calling .add etc. keyvaluepair<tkey,tvalue> treated again pattern logic "auto tuple": has constructor takes of public members, maps them in order (the constructor keyvaluepair(tkey key, tvalue value), .key mapped field 1, , .value mapped field 2). putting together, protobuf-net maps:

[protocontract] class foo {     private readonly sorteddictionary<string, int> items =         new sorteddictionary<string, int>(         stringcomparer.invariantcultureignorecase);     [protomember(1)]     sorteddictionary<string, int> items { {  return items; } } } 

via schema (verifiable via serializer.getproto<foo>()):

message foo {    repeated keyvaluepair_string_int32 items = 1; } message keyvaluepair_string_int32 {    optional string key = 1;    optional int32 value = 2; } 

so basically, should work fine; thing watch ensure custom icomparer<customtkey> gets applied. i've done above giving protobuf-net access getter, , performing collection initiation inside our custom type - use before-deserialization callback same thing if wanted enable constructor-skipping.


Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -