|
-
July 27th, 2006, 12:12 AM
#1
Serialization, why does this work?
I have an object, we can call it ClassA, that are to be serialized. It's containing an arraylist. It looks something like this
Code:
[Serializable()]
public class ClassA {
private ArrayList list;
public ArrayList List {
// get/set
}
public override void GetObjectData(SerializationInfo info, StreamingContext ctxt)
{
info.AddValue("list", list);
}
}
and also a constructor for the deserialization. The thing is that I store objects of type ClassB in my ArrayList. I've marked this class (ClassB) as Serializable but it does not implement ISerializable or has a GetObjectData method. Now the question is: Why is this working? How can the ArrayList populated with ClassB-objects be serialized when there is no serialize-method for ClassB? Because everything works fine and when I deserialize my object, the arraylist contains the same stuff as it did before the serialization.
-
July 27th, 2006, 02:42 AM
#2
Re: Serialization, why does this work?
When you mark a class with the Serializable attribute you don't need to implement the interace ISerializable. The default behavior will occur when there is a need to serialize or deserialize the object.
If you need a special behavior then you should implement the interface.
-
July 27th, 2006, 03:15 AM
#3
Re: Serialization, why does this work?
Which is the default behavior? Because I have other classes, and I need to implement ISerializable in them or otherwise I will get the wrong values (e.g. if a value is true, after serialization/deserialization, it will be false and so on)..but it works on some classes without..
Last edited by EEKstream; July 27th, 2006 at 03:17 AM.
-
July 27th, 2006, 03:25 AM
#4
Re: Serialization, why does this work?
you need to implement this only if you want to serialize data, which is not pubilc or if you have to save some data which isn't serializable.
normally on bool value this should work without problems. maybe you have some other errors or problems in your code...which serializer do you use?
Regards
Hansjörg
-
July 27th, 2006, 04:18 AM
#5
Re: Serialization, why does this work?
I found it, it had nothing to do with the serialization. Thanks, this saved me a lot of code
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|