Quantcast
Viewing all articles
Browse latest Browse all 3

Serialization of objects

I'm trying to do something that I can't really find any help on. I have a class, within this class it represents 2 other classes exposed as properties. I want the properties of the classes to sit under the root of the containing class, instead of having the class names and then values:

Example:

public Origin Origin { get; set; }public Destination Destination { get; set; }

Both these define nodes that should be tagged in the XML as:

<RootClass><ValueFromOrigin /><ValueFromDestination /></RootClass>

Current, my serialization brings back:

<RootClass><Origin><ValueFromOrigin /></Origin><Destination><ValueFromDestination /></Destination /></RootClass>

I have tried adding [XmlElement("RootClass")] to the properties for both Origin and Destination but get an error, assuming that it's trying to duplicate the node for some reason. Has anyone tried this successfully?

Thanks for the help guys.

Eric


Viewing all articles
Browse latest Browse all 3

Trending Articles