Exemplo n.º 1
0
        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("...");
            }
        }
Exemplo n.º 2
0
        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);
            }
        }
Exemplo n.º 3
0
 private SerializerContext DefaultContexFactory(YamlConfig yamlConfig)
 {
     return(new SerializerContext(yamlConfig));
 }
Exemplo n.º 4
0
        /// <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));
        }
Exemplo n.º 5
0
 /// <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));
 }
Exemplo n.º 6
0
 /// <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());
 }
Exemplo n.º 7
0
 /// <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);
 }
Exemplo n.º 8
0
 /// <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);
 }
Exemplo n.º 9
0
 /// <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));
 }
Exemplo n.º 10
0
 public void ToYaml(Stream s, YamlNode node, YamlConfig config)
 {
     using (var yaml = new StreamWriter(s))
         ToYaml(yaml, node, config);
 }
Exemplo n.º 11
0
 public string ToYaml(YamlNode node, YamlConfig config)
 {
     yaml = new StringWriter();
     ToYaml(yaml, node, config);
     return(yaml.ToString());
 }