The emitter writes YAML text from parsing events.
If you are using object mapping, you rarely need the emitter directly. The emitter is most useful for:
The Emitter consumes SharpYaml.Events.ParsingEvent instances.
using System.IO;
using SharpYaml;
using SharpYaml.Events;
var writer = new StringWriter();
var emitter = new Emitter(writer);
emitter.Emit(new StreamStart());
emitter.Emit(new DocumentStart());
emitter.Emit(new MappingStart());
emitter.Emit(new Scalar("name"));
emitter.Emit(new Scalar("Ada"));
emitter.Emit(new Scalar("age"));
emitter.Emit(new Scalar("37"));
emitter.Emit(new MappingEnd());
emitter.Emit(new DocumentEnd());
emitter.Emit(new StreamEnd());
var yaml = writer.ToString();
If you are using the model layer (SharpYaml.Model), you can write it back through the emitter:
using SharpYaml.Model;
var stream = YamlStream.Load(new StringReader("a: 1\n"));
var doc = stream[0];
var sb = new StringWriter();
doc.WriteTo(sb);
Emission is influenced by options such as:
WriteIndented, IndentSize)MappingOrder)ScalarStylePreferences)For object mapping, these are configured through YamlSerializerOptions. For low-level emission, the emitter has its own tuning knobs (canonical mode, indentation, width).