Wrapping Serialized Array Elements with the Name of the Array

前端 未结 2 378
滥情空心
滥情空心 2021-01-14 08:45

I am using VSTS2008 + C# + .Net 3.0. I am using below code to serialize XML, and my object contains array type property, and I want to add an additional elements\' layer (\

相关标签:
2条回答
  • 2021-01-14 08:50
        ...
        [XmlArray(IsNullable = false)]
        [XmlArrayItem("MyInnerObjectProperties")]
        public MyObject[] MyObjectProperty
        {
            get
            {
                return _myObjectProperty;
            }
            set
            {
                _myObjectProperty = value;
            }
        }
        ...
    
    0 讨论(0)
  • 2021-01-14 09:13

    make use of the XmlArrayItemAttribute

    [XmlArray("MyInnerObjectProperties")]     
    [XmlArrayItemAttribute("MyInnerObjectProperty", typeof(MyInnerObject),  IsNullable = false)]
    public MyInnerObject[] MyInnerObjectProperty
    {
       get
         {
             return _myInnerObjectProperty;
         }
       set
         {
            _myInnerObjectProperty = value;
         }
    }
    
    0 讨论(0)
提交回复
热议问题