3

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; }
}
synapse
  • 5,588
  • 6
  • 35
  • 65
  • @dymanoid Nothing so far. It seems that custom `INodeDeserializer` is needed but I haven't dug into yet thinking someone has already done that – synapse Jun 02 '17 at 14:53
  • It looks like this can be done implementing `IYamlTypeConverter`. Unfortunately, this appears to require manually coding the serialization/deserialization logic for everything - as far as I can tell we cannot use any of the YamlDotNet serialization/deserialization logic when we do this. Which is really not much help at all... sorry – Yoshiya Jun 05 '18 at 13:46
  • I'm new to YamlDotNet, but I think you need a custom naming convention to drop the `s` (convert from plural widgets to WidgetList). – yzorg Feb 27 '19 at 20:48

0 Answers0