c# inheriting generic collection and serialization

前端 未结 5 2115
礼貌的吻别
礼貌的吻别 2020-12-06 13:36

The setup:

class Item
{
    private int _value;

    public Item()
    {
        _value = 0;
    }

    public int Value { get { return _value; } set { _valu         


        
5条回答
  •  温柔的废话
    2020-12-06 13:58

    I am not sure if I am missing something, but do you want the resulting xml to be

    
       name val
       
          1
       
          2
       
    

    If so, just apply the XmlRoot attribute to the itemcollection class and set the element name...

    [XmlRoot(ElementName="ItemCollection")]
    public class ItemCollection : Collection
    {
       [XmlElement(ElementName="Name")]
       public string Name {get;set;}
    }
    

    This will instruct the serializer to output the required name for you collection container.

提交回复
热议问题