How to suppress XML tag for list property

前端 未结 1 1157
悲哀的现实
悲哀的现实 2021-01-02 07:06

Is it possible to avoid list property tags when serializing?

//[Serializable()] - removed, unnecessary
public class Foo
{
    protected List fo         


        
相关标签:
1条回答
  • 2021-01-02 08:00

    Adding:

    [System.Xml.Serialization.XmlElement("FooBar")]
    public virtual List<FooBar> FooBars 
    { 
        get { return fooBars; } 
        set { fooBars = value; }
    }
    

    Results in

    <FooMain xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http:/
    /www.w3.org/2001/XMLSchema">
      <FooBar>
        <MyProperty>7</MyProperty>
      </FooBar>
      <FooBar>
        <MyProperty>76</MyProperty>
      </FooBar>
      <FooBar>
        <MyProperty>67</MyProperty>
      </FooBar>
    </FooMain>
    
    0 讨论(0)
提交回复
热议问题