问题
The title says pretty much what I would like to know. I have data which was binary serialized and now I'm reading it again (class name remains the same) and I would like to know if the serializer misses something because, for example, a private backing field might have been renamed.
I did the following refactoring:
private string descriptionField;
public string Description
{
get { return this.descriptionField; }
}
to
public string Description { get; private set; }
As stated in in this article this won't work. But I really would like to know if there is a way to detect if the class does not match the serialized data.
I do not want to do the serialization myself via implementing ISerializable
because the class and its properties is quite large and might be changed. I'd prefer a easier solution =)
回答1:
But I really would like to know if there is a way to detect if the class does not match the serialized data?
One way to detect it would be to serialize the existing class with the same data as in the previous serialized file and then compare the digital fingerprints of the previous and current serialized files.
I do not want to do the serialization myself via implementing ISerializable because the class and its properties is quite large and might be changed.
Since you are using the BinaryFormatter and dealing with potentially significant versioning issues, i think your only option is to implement ISerializable
and handle deserialization yourself whether you like it or not.
来源:https://stackoverflow.com/questions/26510721/check-whether-binary-serialized-data-matches-the-class-which-serialized-it