Lee Atkinson
Lee Atkinson

Reputation: 2189

XmlTextAttribute equivalent in DataContracts

Is there an equivalent to XmlTextAttribute when using DataContractSerializer?

I want to treate a property as the 'default property when it is serialized to XML. For example:

[Serializable]
[DataContract]
public class Item
{
    [DataMember]
    public String Value
    {
        get;
        set;
    }
}

A object with .Value set to "foo" is serialized as:

<Item>foo</Item>

rather than:

<Item><Value>foo</Value></Item>

Lee

Upvotes: 0

Views: 261

Answers (1)

marc_s
marc_s

Reputation: 755187

I don't think you can do that using the DataContractSerializer.

Marc

Upvotes: 1

Related Questions