DefaultValue properties deserialization

谁说胖子不能爱 提交于 2019-12-10 18:37:43

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/16649924/defaultvalue-properties-deserialization

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!