1

I use YamlDotnet to parse a yaml stream to a dictionary of string object via the YamlStream. The YamlMappingType, YamlSequenceNode and YamlScalarNode are used in order to convert the value to a dictionary, a list or a string.

But I need to get a real boolean value instead of the string equivalent, and for that I use

bool.TryParse(value.ToString(), out valueBool)

value veing a YamlNode.

Is there a better way to do that? Perhaps another child type of YamlNode?

EDIT: I don't know the content of the YAML file, I just want to get a dictionary with his values.

Jérémie Bertrand
  • 3,025
  • 3
  • 44
  • 53

1 Answers1

0

Instead of doing the parsing manually, you should use the Deserializer class, which will convert a YAML document into an object graph.

var deserializer = new Deserializer();
var parsed = deserializer.Deserialize<...>(input);

You can see a working example here

Antoine Aubry
  • 12,203
  • 10
  • 45
  • 74