Подскажите, как сериализовать класс с коллекцией вида ObservableCollection`?
Пытаюсь делать на классе Example
.
public class Animal
{
public string Sound { get; set; }
}
[Serializable]
public class Example
{
public string Properties1 { get; set; } = "nothing";
public bool Properties2 { get; set; }
public static ObservableCollection<Animal> MyCollection { get; set; } = new ObservableCollection<Animal>();
public Example()
{
MyCollection.Add(new Animal() { Sound = "Мяу"});
MyCollection.Add(new Animal() { Sound = "Гав" });
}
}
Сериализую так, но сериализуются только свойства:
Example example = new Example();
XmlSerializer formatter = new XmlSerializer(typeof(Example));
using (FileStream fs = new FileStream("test.xml", FileMode.OpenOrCreate))
{
formatter.Serialize(fs, example);
}