If I have a class with many child classes and I use ObjectSerializer.SerializeObject will it also serialize the child classes as well?
+4
A:
Serializers do not serialize classes. They serialize instances (and graphs of instances).
An instance of a class does not automatically contain an instance of any of its nested classes. Similarly, an instance of the nested class also does not automatically contain an instance of the outer class.
If you serialize an instance of the outer class, the serializer will serialize an instance of the nested class if and only if the object graph contains one. In this respect, nested classes are exactly the same as all other classes.
Timwi
2010-09-13 14:00:16
So it will work?
zachary
2010-09-13 15:06:45
@zachary: You cannot avoid trying to understand this. Until you do, it will not work. Nothing will.
Timwi
2010-09-13 16:49:05
It didn't work... for the record I made a class that wrapped XmlSerializer and put that up here by accident. I guess one of the nested classes could not be serialized.
zachary
2010-09-14 19:42:19