Serializing a class containing a custom class

alkaline

New Member
I want to serialize an object as xml that contains other custom classes. From what I understand (I've been reading MSDN and SO mostly), the \[code\]XmlSerializer\[/code\] doesn't take this into account.This is the line that's confusing me: \[quote\] XML serialization serializes only the public fields and property values of an object into an XML stream. XML serialization does not include type information. For example, if you have a Book object that exists in the Library namespace, there is no guarantee that it will be deserialized into an object of the same type.\[/quote\]Taken from MSDN, hereFor example, I want to serialize an object of type \[code\]Order\[/code\], but it contains a list of \[code\]Products\[/code\], and each one contains an object of type \[code\]Category\[/code\]:\[code\]class Order{ List<Product> products;}class Product{ Category type;}class Category{ string name; string description;}\[/code\]And I want my \[code\]Order\[/code\] object to be serialized like so:\[code\]<Order> <Product> <Category Name=""> <Description></Description> </Category> </Product> <Product> <Category Name=""> <Description></Description> </Category> </Product><Order>\[/code\]Does the \[code\]XmlSerializer\[/code\] already do this? If not, is there another class that does or do I have to define the serialization process myself?
 
Back
Top