TamKap
TamKap

Reputation: 159

How serialize Base class properties for multiple derived classes, ProtoBuf.net

I'm intereseted if there is any way to serialize base class properties from multiple derived classes without writing [ProtoInclude(n, typeof(DerivedM))] attribute for all derived classes.

Upvotes: 1

Views: 85

Answers (1)

Marc Gravell
Marc Gravell

Reputation: 1062502

That is the preferred mechanism. You can automate it via reflection and manipulating the RuntimeTypeModel[typeof(TheBaseType)] (there are methods to add sub-types, etc) - however, this is brittle: it is very important that the same keys (numbers) map to the same types in the future, even if you add/remove/rename types. Additionally, explicitly declaring the support makes it easy to see which keys (field numbers) are in use.

Upvotes: 1

Related Questions