WCF DataMember List<> without enclosing element

前端 未结 2 1125
时光说笑
时光说笑 2021-01-20 19:28

The following DataContract:

    [DataContract(Namespace = \"http://namespace\", Name = \"Blarg\")]
    public class Blarg
    {
        [XmlAttribute(\"Attri         


        
2条回答
  •  感情败类
    2021-01-20 19:47

    I don't think you can do that.

    The DataContractSerializer is optimized for speed, and in the process it sacrifices some flexibility and some features (like XML attributes). I don't think you have much chance to influence the DCS - it does its job as it sees fit, and as quickly as possible. You get to define quite neatly what to serialize (with the [DataMember] attribute, but you don't really have a say in how to serialize.

    If you need more control, you could pick the XmlSerializer instead - in that case, you have 10-15% slower serialization, but you can control things like the shape of the data etc. But even in this case - I am not aware of any way you can tell the XML serializer to serialize a collection into a series of XML tags without an enclosing tag for the collection.

提交回复
热议问题