Why classes are not serializable by default in .Net?

后端 未结 5 1673
日久生厌
日久生厌 2021-02-06 23:51

Developers have to \'opt in\' for making classes serializable by explicitly using SerializableAttribute. What could go wrong if classes were serializable by default

5条回答
  •  你的背包
    2021-02-07 00:30

    The Liskov Substitution Principle implies that if a class is serializable, all derived classes should be serializable as well. If classes were by default serializable, it would be very difficult to derive non-serializable classes without violating the Liskov Substitution Principle.

提交回复
热议问题