1

YamlDotNet seems to support serializing POC graphs, but I can't find an API that serializes an object graph made directly of YamlNode types. Is there a way to do this?

Andrew Arnott
  • 80,040
  • 26
  • 132
  • 171

1 Answers1

0

The trick is to pass the root node into a new YamlDocument and then to pass the document to YamlStream, which exposes a Save method.

var rootNode = new YamlMappingNode();
rootNode.Add("methods", methods);
var result = new YamlDocument(rootNode);
var resultStream = new YamlStream(result);
using var resultWriter = File.CreateText(@"d:\temp\scraped.yml");
resultStream.Save(resultWriter);
Andrew Arnott
  • 80,040
  • 26
  • 132
  • 171