-
Serializable class
Hello guys and gals,
I've written classes with serializable attribute before but all of them were just "standalone" classes. By saying "standalone", I mean the class itself does not refer to other custom classes within the same application.
Now I have a need to write a serializable class that DOES refer to my other custom classes. For example, I have ClassA and ClassB. ClassB will be serializable. One of the properties in classB returns a ClassA object. My question is, in order for classB to be serializable, does ClassA also needs to be serializable?
Thanks for any inputs.
Stanav.
-
Re: Serializable class
I don't believe so.
[edit]
I should explain my thinking. You could create a new non-serializable class with a property that holds a dataset object, which is serializable.
-
Re: Serializable class
For a moment I read that backwards.... W_B is right, the containing class doesn't need to be serializable. Been there, done that. I have a couple t-shirts.
It's the going the other way that isn't as straight forward.
-tg
-
Re: Serializable class
If a method returns a type, it doesn't have any impact on serializability. If a type is a member of a different type, then for the containing type to be serialized, all of its members have to support serialization. However, since you said that B returned an A, that sounds like a method returning a type, which has nothing to do with serialization.
-
Re: Serializable class
Shaggy, it's a property in ClassB that has ClassA type... I don't know if a property would make any difference than a method (function)...
-
Re: Serializable class
If the property creates a new instance of A and returns it, then you are all set. If the property is just exposing an instance of A that is a member of B, then A has to be serializable. The serialization only affects the data portion of a class.
-
Re: Serializable class
Why don't you try it out?
-
Re: Serializable class
Yeah, the property itself isn't serialized, only the data members are.