Binary serialization questions
-
I need to serialize object of my class. I derives from a class which is not serializable. The questions: 1) Do I have to implement the ISerializable interfaace in my class? 2) Are enums serializable?? I have several enum fields in my class. Thanks!
-
I need to serialize object of my class. I derives from a class which is not serializable. The questions: 1) Do I have to implement the ISerializable interfaace in my class? 2) Are enums serializable?? I have several enum fields in my class. Thanks!
#1 Just put the serializable attribute atop your class #2 Yes they are and will be automatically, if used in your serializable class the class you are deriving from not being serializable should not be a problem unless the class does some stuff that almost deliberlately makes it nonserializable. Give it a try, it should work flawlessly. Use the .NET serialization routines to save and restore your class, you'll find it works quite easily. Use the .NET Binary serializer in your main code to save/restore these class objects.
-
#1 Just put the serializable attribute atop your class #2 Yes they are and will be automatically, if used in your serializable class the class you are deriving from not being serializable should not be a problem unless the class does some stuff that almost deliberlately makes it nonserializable. Give it a try, it should work flawlessly. Use the .NET serialization routines to save and restore your class, you'll find it works quite easily. Use the .NET Binary serializer in your main code to save/restore these class objects.
#1 Just put the serializable attribute atop your class That won't work if the class he's extending is not serializable. From the MSDN[^]: "It is important to note that the Serializable attribute cannot be inherited. If you derive a new class from MyObject, the new class must be marked with the attribute as well, or it cannot be serialized. For example, when you attempt to serialize an instance of the class below, you will get a SerializationException informing you that the MyStuff type is not marked as serializable". The only way around it is to use
ISerializable
"I think I speak on behalf of everyone here when I say huh?" - Buffy