Esempio n. 1
0
        /// <summary>
        /// Writes the content of this YAML node to the specified writer.
        /// </summary>
        /// <param name="writer">The writer to output YAML to.</param>
        public void WriteTo(TextWriter writer)
        {
            if (writer == null)
            {
                throw new ArgumentNullException(nameof(writer));
            }
            var preferredIndent = YamlSerializer.GetSerializerSettings().PreferredIndent;

            yamlStream.Save(writer, true, preferredIndent);
            writer.Flush();
        }
Esempio n. 2
0
        public static T ConvertTo <T>(IDynamicYamlNode yamObject)
        {
            using (var memoryStream = new MemoryStream())
            {
                // convert Yaml nodes to string
                using (var streamWriter = new StreamWriter(memoryStream))
                {
                    var yamlStream = new YamlStream {
                        new YamlDocument(yamObject.Node)
                    };
                    yamlStream.Save(streamWriter, true, YamlSerializer.GetSerializerSettings().PreferredIndent);

                    streamWriter.Flush();
                    memoryStream.Position = 0;

                    // convert string to object
                    return((T)YamlSerializer.Deserialize(memoryStream, typeof(T), null));
                }
            }
        }