GromHellscream
GromHellscream

Reputation: 111

DefaultValue properties deserialization

I'm trying to deserialize stream to object with default value properties and protobuf-net just ingores this properties when they are missing in the stream. Do i need to manually set before deserialization all properties to their default values or that?

Upvotes: 3

Views: 512

Answers (1)

Marc Gravell
Marc Gravell

Reputation: 1062780

The DefaultValues behavior (not just in protobuf-net - in System.ComponentModel generally, for example PropertyGrid, PropertyDescriptor, etc) is that this is used to indicate things that don't need to be serialized, because they will be defaulted to that same value automatically. As such, it assumes that if your code annotates a DefaultValue, then your code will be assigning those defaults. This could be in a constructor, field-intializer, or in a pre-deserialization callback (all 4 standard callback points are supported).

Technically, it would not be impossible for the library to explicitly assign these values prior to deserialization - but simply: that isn't what is coded currently.

Upvotes: 4

Related Questions