public void ToYaml(TextWriter yaml, YamlNode node, YamlConfig config) { this.config = config; this.yaml = yaml; this.indent = new string(' ', config.IndentCount); MarkMultiTimeAppearingChildNodesToBeAnchored(node); yaml.NewLine = config.LineBreakForOutput; column = 1; raw = 1; if (config.EmitYamlVersion) { WriteLine("%YAML 1.2"); } if (config.EmitStartAndEndOfDocument) { WriteLine("---"); } NodeToYaml(node, "", Context.Normal); if (config.EmitStartAndEndOfDocument) { WriteLine("..."); } }
static YamlNode() { // Initializing order matters ! DefaultTagPrefix = "tag:yaml.org,2002:"; DefaultConfig = new YamlConfig(); DefaultParser = new YamlParser(); DefaultPresenter = new YamlPresenter(); DefaultSerializerContext = new SerializerContext(DefaultConfig); foreach (var shortToLongTag in ShortToLongTags) { LongToShortTags.Add(shortToLongTag.Value, shortToLongTag.Key); } }
private SerializerContext DefaultContexFactory(YamlConfig yamlConfig) { return(new SerializerContext(yamlConfig)); }
/// <summary> /// Convert YAML text <paramref name="yaml"/> to a list of <see cref="YamlNode"/>. /// </summary> /// <param name="tr"><see cref="TextReader"/> from which YAML document is read.</param> /// <returns>YAML nodes</returns> /// <param name="config"><see cref="YamlConfig">YAML configuration</see> to customize serialization.</param> public static YamlNode[] FromYaml(TextReader tr, YamlConfig config) { var yaml = tr.ReadToEnd(); return(FromYaml(yaml, config)); }
/// <summary> /// Convert YAML text <paramref name="yaml"/> to a list of <see cref="YamlNode"/>. /// </summary> /// <param name="s"><see cref="Stream"/> from which YAML document is read.</param> /// <returns>YAML nodes</returns> /// <param name="config"><see cref="YamlConfig">YAML configuration</see> to customize serialization.</param> public static YamlNode[] FromYaml(Stream s, YamlConfig config) { using (var sr = new StreamReader(s)) return(FromYaml(sr, config)); }
/// <summary> /// Convert YAML text <paramref name="yaml"/> to a list of <see cref="YamlNode"/>. /// </summary> /// <param name="yaml">YAML text</param> /// <returns>YAML nodes</returns> /// <param name="config"><see cref="YamlConfig">YAML configuration</see> to customize serialization.</param> public static YamlNode[] FromYaml(string yaml, YamlConfig config) { return(DefaultParser.Parse(yaml, config).ToArray()); }
/// <summary> /// Convert <see cref="YamlNode"/> to a YAML text and save it to <see cref="TextWriter"/> <paramref name="tw"/>. /// </summary> /// <param name="tw"><see cref="TextWriter"/> to output.</param> /// <param name="config"><see cref="YamlConfig">YAML configuration</see> to customize serialization.</param> public void ToYaml(TextWriter tw, YamlConfig config) { DefaultPresenter.ToYaml(tw, this, config); }
/// <summary> /// Convert <see cref="YamlNode"/> to a YAML text and save it to <see cref="Stream"/> <paramref name="s"/>. /// </summary> /// <param name="s"><see cref="Stream"/> to output.</param> /// <param name="config"><see cref="YamlConfig">YAML configuration</see> to customize serialization.</param> public void ToYaml(Stream s, YamlConfig config) { DefaultPresenter.ToYaml(s, this, config); }
/// <summary> /// Convert <see cref="YamlNode"/> to a YAML text. /// </summary> /// <returns>YAML stream.</returns> /// <param name="config"><see cref="YamlConfig">YAML configuration</see> to customize serialization.</param> public string ToYaml(YamlConfig config) { return(DefaultPresenter.ToYaml(this, config)); }
public void ToYaml(Stream s, YamlNode node, YamlConfig config) { using (var yaml = new StreamWriter(s)) ToYaml(yaml, node, config); }
public string ToYaml(YamlNode node, YamlConfig config) { yaml = new StringWriter(); ToYaml(yaml, node, config); return(yaml.ToString()); }