Serializing object that inherits from List

前端 未结 1 1081
面向向阳花
面向向阳花 2021-01-19 08:24

When I try to serialize this collection, the name property is not serialized.

public class BCollection : List where T : B_Button
{       
          


        
1条回答
  •  清酒与你
    2021-01-19 09:03

    In many serializers (and data-binding, in fact), an object is either an entity or (exclusive) a list; having properties on a list is not commonly supported. I would refactor to encapsulate the list:

    public class Foo {
        public string Name {get;set;}
        private readonly List items = new List();
        public List Items { get { return items; } }
    }
    

    Also; how would you plan on representing that in JSON? IIRC the JSON array syntax doesn't allow for extra properties either.

    0 讨论(0)
提交回复
热议问题