How to serialize an included object/property as a root?

FoettyQuego

New Member
I've got a tough problem. Let's say I have a class named \[code\]ObjectHost\[/code\], containing a property of type \[code\]BusinessObject\[/code\], which itself contains some properties (let's say a \[code\]Name\[/code\] and a \[code\]Town\[/code\] as strings).The code would be :\[code\]public class ObjectHost{ public BusinessObject Data { get; set; } public ObjectHost() { Data = http://stackoverflow.com/questions/10723302/null; } public ObjectHost(BusinessObject ei) { Data = ei; } public override string ToString() { return (Data == null) ?"null" : Data.ToString(); }}\[/code\]When serializing, it will produce something like :\[code\]<ObjectHost> <Data> <Name>My name</Name> <Town>London</Town> </Data></ObjectHost>\[/code\]Where I'd like it to be :\[code\]<Name>My name</Name><Town>London</Town>\[/code\]as it is only an encapsulation object in my particular use (for some other purposes).I tried using \[code\]XmlRoot\[/code\] and \[code\]XmlElement\[/code\] attributes but I didn't achieve my goal.Is there a solution for this ?
 
Back
Top