I've trying to serialize and deserialize a list with an interface, the problem is that yamldotnet cannot deserialize it.
I've show it to you with an example:
interface IAnimal
{
string Name { get; }
}
class Cat : IAnimal
{
public string Name { get; set; }
public string CustomThing { get; set; } = "1a";
}
class Dog : IAnimal
{
public string Name { get; set; }
public bool IsSomething { get; set; } = true;
}
When I now try to serialize this:
var serializer = new Serializer();
List<IAnimal> animals = new List<IAnimal>()
{
new Cat() { Name = "Oscar" },
new Dog() { Name = "WuffWuff" }
};
var writer = File.CreateText("test.yml");
serializer.Serialize(writer, animals);
writer.Close();
The result of this would be
- Name: Oscar
CustomThing: 1a
- Name: WuffWuff
IsSomething: true
I understand that as this point yamldotnet cannot know which types that are, and it is needed that the class types are also definied inside the yml
So how can I archive this?
I've already tried to find something in the documentation but there are only examples and nothing with interfaces / list's.