简体   繁体   中英

Custom Serialization of base class properties

I have a class that is implementing the ISerializable interface for custom serialization. This works great for the properties in this class but the class is a derived class. The problem i'm running into is that the base class properties aren't serialized for me. The base class has the serializable attribue but doesnt implement ISerializable. Is there a way to serialize the base class properties without having to add all of them manually in the derived class's ISerializable .GetObjectData method?

From 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM