Why my ObservableCollection serialization doesn't work?

后端 未结 2 761
既然无缘
既然无缘 2021-01-20 21:51

I\'m trying to serialize and deserialize this ObservableCollection:

public class DataCollection : ObservableCollection
{
}

public class Data : I         


        
2条回答
  •  一个人的身影
    2021-01-20 22:31

    1. Your Data class must have a parameter less constructor, otherwise XmlSerializer will never be able to create instance of Data.
    2. Instead of storing DataCoollection, you should store and retrieve Data[], it's easier without having to do anything else.
    3. While storing, you can call ToArray method to get Data[] and use typeof(Data[]) for serializer.
    4. While reading you can read the array and add items into your collection.

提交回复
热议问题