I do not think this is a duplicate. I read something, but did not find anything like it. It seems that the fields can be serialized in binary formats and in protobuf, but not in XML. I do not know about JSON.
I am considering replacing the standard .NET binary serializer with protobuf-net. The reason is to increase speed and get a smaller file size.
In NET Binary, I simply designated the classes as serializable and left them to that. Not good, I suspect.
With protobuf-net, I need to specify what is serialized with the [ProtoMember ()] attribute. My newbie test shows that private fields become serialized if they are marked as automatic properties.
I donβt want to change the class code definitions at all, because I still need to be able to deserialize the old stored data created by the NET serializer. I have a mixture:
- Private fields that are used inside the class
- Private fields whose value is set in the constructors
- Private fields that support fields for non-automatic properties
- Properties with top margins above
- Auto properties
- Properties without setters that return some calculation or value defined internally
and maybe some others. In other words, almost all types of fields and properties.
I assume that I need to save any value that represents the state of an object that cannot be created after deserialization from a file.
I believe that there would be no harm in saving each field and property, but that would just make the work slower and the file larger than it should be.
I think I can ignore private fields that are used only inside the class and are not set externally. I think I should persist in the fields that are set in the constructors. I am not sure about the support of the fields - is it better to preserve them or their public property? I have to save auto properties. I cannot save properties without settings, so I need all the fields / properties to be used in their calculations.
I am on the right track or missing a point.
Thanks in advance.
source share