ObjectSerializer.SerializeObject and nested classes
I开发者_开发知识库f I have a class with many child classes and I use ObjectSerializer.SerializeObject will it also serialize the child classes as well?
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.
精彩评论