c# serialize nested class

前端 未结 3 1549
无人及你
无人及你 2021-01-16 09:19

I\'m trying to serialize a dummy collection of orders, where each order contains a product. The collection is serializing fine, but the example product properties inside the

相关标签:
3条回答
  • 2021-01-16 09:46

    Change into List.

    Public List Products {

    }

    0 讨论(0)
  • 2021-01-16 09:49

    You have to change ICollection to List. An interface isn't serializeable.

    [XmlArray("Products")]
    public List<Product> Products
    {
        get
        {
            return this._products;
        }
    
    }
    

    And ProductTest doesn't work because of the missing setter

    0 讨论(0)
  • 2021-01-16 09:51

    You can't serialize an interface..

    An interface is nothing more than a description of a set of behaviors. It says nothing about the contents of an instance. In particular, although an instance of a class implementing an interface must implement all of its members, it will certainly have properties of its own which need to be serialized.

    PS: copied from Serializing interfaces

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