Serialized Version Files

I have a working application that serializes a document (of type IDocument) to disk. From there, there is another application that I made to open this document (IDocument implements IPrintDocument) for viewing.

Suppose I wrote an IDocument to disk, and then after a week the field is added to the IDocument. Both the program that writes the files and the one that opens them are updated with this new "version" of IDocument. Then it will break (I assume that I did not have the opportunity to check if I look here) when trying to open a previous version of IDocument. Is there a known pattern that alleviates this problem?

+3
source share
3 answers

Yes - Use a serialization engine that is tolerant of version control .

As expected, I suggest using Google Protocol Buffers , for which there are at least two viable .NET implementations. As long as you are careful, the protocol buffers are compatible with both reverse and direct access - you can read a new message with the old code and vice versa, and the old code can still save information that it does not understand.

Another alternative is XML, whether it uses the built-in XML serialization or not. To my knowledge, inline serialization is not particularly flexible in terms of version control.

+4

.net - , , , .

/, :

[XmlAnyElement()]
public XmlElement[] ExtendedElements { get; set; }
[XmlAnyAttribute()]
public XmlAttribute[] ExtendedAttributes { get; set; }

, , /, , , . , . .

, .

: , XML. , . / , (.net 2.0+), , , .

.net 2.0, - , , . , , xml.

: http://msdn.microsoft.com/en-us/library/system.runtime.serialization.serializationbinder.aspx, http://msdn.microsoft.com/en-us/library/ms229752.aspx

XML, .

Ps. , - , , .

+3

[OptionalField]. , , , , ..

Another couple of options would be to use the embedded DB, for example Sqlite for your document store. And manually (or using ORM) the properties / fields of the map in your object into the columns of the table.

or

Use Lucene , which will also give you a full-text search through your documents.

+1
source

Source: https://habr.com/ru/post/1705369/


All Articles