All classes whose instances must / can be stored via BinaryFormater must have this very same [Serializable] attribute. Why is it needed?
No, of course, it is clear that he says the CLR environment, they say, the type is serializable, therefore, be good (medium) and serialize!
In my view, almost on the fingers , this attribute helps MSV to add and implement the GetObjectData(SerializationInfo info, StreamingContext context) from the ISerializable interface for each field in the class. For example:
public override void GetObjectData(SerializationInfo info, StreamingContext context) { info.AddValue("Name", name); info.AddValue("BDate", BDate); info.AddValue("Price", Price); } And implement a constructor for deserialization, like this:
public Engineer(SerializationInfo info, StreamingContext context) : base(info.GetString("Name"), info.GetDateTime("BDate")) { Price = info.GetDecimal("Price"); } BUT, even if you implemented the ISerializable interface, the attribute is still needed. CA2237: MarkISerializableTypesWithSerializable
What is he doing all the same, so to speak, under the hood ?