Polymorphic deserialization with object root

Viewed 376

What's the best way do deserialize the following YAML file

widgets:
  square:
    color: red
  circle:
    color: blue

into this class hierarchy?

public abstract class Widget {
    public string Color { get; set; }
}

public class Square : Widget { }

public class Circle : Widget { }

public class WidgetList {
    public IEnumerable<Widget> Widgets { get; set; }
}
0 Answers
Related