I have been reading about protobuf-net and it is amazing!
Are there any tutorials that I could use? (More specifically for Dictionary<TKey,TValue>
and contracts for generics)
Are there any tips associated with it?
Could I simply plug it into my current codebase or are there any changes I need to do?
Dictionary<TKey,TValue>
should largely just work (in "v1" at least; I haven't written that yet for "v2").
I fully admit that the documentation is... sparse. Things that leap to mind:
I have a lot happening at the moment (I've just changed jobs, etc), but my priorities are:
Time is my biggest enemy. But if you have a specific scenario, feel free to ping me and I'll try to get back to you ASAP.
Re "can I simply plug it in"; that depends on your code ;-p
It needs some way of determining a unique number for each member that you want to serialize. The simplest way to do this is via attributes; it supports any of [XmlElement(Order=n)]
, [DataMember(Order=n)]
or [ProtoMember(n)]
. If you already have at least one of these (LINQ-to-SQL includes [DataMember]
, for example) then it may simply work.
There are options to automatically infer the numbers, but that is brittle and not recommended. Only use this if you know you never need to add more members (it orders them alphabetically, so adding a new AardvarkCount
will break everything).
In "v2" (unreleased, but works), you can now handle the metadata independently of the types - i.e. you can use protobuf-net with POCO, unattributed types. You can also bypass the constructors etc (WCF-style). Much more flexible, if you want it. The attribute approach is supported too, of course.