WCM List DataMember <> without a closing element

Next DataContract:

    [DataContract(Namespace = "http://namespace", Name = "Blarg")]
    public class Blarg
    {
        [XmlAttribute("Attribute")]
        public string Attribute{ get; set; }

        [DataMember(Name = "Record", IsRequired = false, Order = 4)]
        public List<Record> Record{ get; set; }
    }

Serializes to the following:

<Blarg Attribute="blah">
    <Record>
        <Record/>
        <Record/>
        <Record/>
    </Record>
</Blarg>

But I want this:

<Blarg>
    <Record/>
    <Record/>
    <Record/>
<Blarg/>

The DataContractSerializer seems to automatically insert the parent header, and I don't want it.

How do I remove a wrapper <Record>?

+3
source share
2 answers

I do not think you can do this.

DataContractSerializer , ( XML). , DCS - . , ( [DataMember], , .

, XmlSerializer - 10-15% , , .. - , XML, XML- .

+2

. . ( URL):

 [XmlElement ("Parameter")]
    public List<Parameter> Parameters;
0

Source: https://habr.com/ru/post/1755031/


All Articles