I assume it looks at your model and somehow gets things ready, so that your first few serializations aren’t slowed. What if my messaging model has a message class with child classes? Does putting my parent class in the type argument prepare all the children too?
Share
(this answer assumes protobuf-net v2)
If you mean
Serializer.PrepareSerializer<T>(), then it will certainly inspect all the child-types, so the type-model will be prepared for them (meaning: it will figure out what fields/properties etc need serializing). It will pre-compile (i.e. IL-emit) the code for the parent class, but (looking at the code) not specifically for the derived types. If unattended, the derived types will compile themselves when first needed. I think! I can do a thorough check if you really want.However, if you use
RuntimeTypeModel.Default.CompileInPlace(), it builds the entire model – everything known is prepared. Of course, that then leaves the dilemma of having to tell the model about them first ;pI’ll double check to see at what point the sub-type serializers are prepared, just to be sure. It might indeed make sense to cascade them.
Update:
it looks like it does indeed cascade to derived types, but not to the parent type (if any):
Here, the second test passes; the first test fails citing “A” – so the sub-types (“C” and “D”) were fully compiled. Since the base type will still get compiled on demand, this is probably fine as-is, but I could probably make it tract to ancestor types if that would be useful.
(the
IsPreparedmethod only exists in my local copy)