views:

351

answers:

2

Assume I have a C# class like this:

[XmlRoot("floors")]
public class FloorCollection
{
    [XmlElement("floor")]
    public Floor[] Floors { get; set; }

}

And I want to serialize it and send to a REST API using WCF. But before sending I need adding an attribute to the floors node in this way: <floors type="array">...</floors>

Any idea?

+3  A: 

Just add the type attribute into your collection class:

[XmlRoot("floors")]
public class FloorCollection
{
    [XmlAttribute("type")]
    public string Type { get; set; }
    [XmlElement("floor")]
    public Floor[] Floors { get; set; }

}
tomasr
+2  A: 

If you mean adding that without the business code knowing about it, then you'll probably have to use Message Inspectors to modify the message before it is sent.

Philippe