The reading class (immutable) of the serializable class

I developed a class with two properties - both a string type and a list of objects. I load xml and deserialize it into an instance of a class that works very well. I want everything about each instance to be immutable. These classes are displayed as APIs, and for integrity, I do not want to change the values ​​of the object. If the programmer wants something else, they must create new instances and set the values ​​then.

I usually did this using the ReadOnlyCollection and readonly properties, but this interferes with deserialization. What can i do here?

+3
source share
3 answers

, XML-, ISerializable , .

void GetObjectData(SerializationInfo info, StreamingContext context)
{
  // ...
}
+2

ISerializable . , , , - .

0

Implement the ISerializable interface and do it manually

0
source

All Articles