Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DefaultValue properties deserialization

Tags:

protobuf-net

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?

like image 656
GromHellscream Avatar asked Jan 22 '26 06:01

GromHellscream


1 Answers

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.

like image 117
Marc Gravell Avatar answered Jan 27 '26 00:01

Marc Gravell



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!