我有一个类正在实现用于自定义序列化的 ISerializable 接口(interface)。这对此类中的属性非常有用,但该类是派生类。我遇到的问题是基类属性没有为我序列化。基类具有可序列化属性,但未实现 ISerializable。有没有一种方法可以序列化基类属性,而不必在派生类的 ISerializable .GetObjectData 方法中手动添加所有属性?
请您参考如下方法:
来自 MSDN
As I mentioned, the ISerializable interface is extremely powerful since it allows a type to take complete control over how instances of the type get serialized and deserialized. This power comes at a cost; the type is now responsible for serializing all of its base type's fields as well. Serializing the base type's fields is easy if the base type also implements the ISerializable interface—you just call the base type's GetObjectData method. Someday you may find yourself defining a type that needs to take control of its serialization, but whose base type does not implement the ISerializable interface. In this case, your class must manually serialize the base type's fields.
