public void RoundtripDictionary()
        {
            Dictionary <string, string> entries = new Dictionary <string, string>
            {
                { "key1", "value1" },
                { "key2", "value2" },
                { "key3", "value3" },
            };

            var serializer   = new Serializer();
            var deserializer = YamlSerializer.Create(entries, YamlSerializerModes.Roundtrip | YamlSerializerModes.DisableAliases);

            StringWriter buffer = new StringWriter();

            serializer.Serialize(buffer, entries);

            Console.WriteLine(buffer.ToString());

            var deserialized = deserializer.Deserialize(new StringReader(buffer.ToString()));

            foreach (var pair in deserialized)
            {
                Assert.Equal(entries[pair.Key], pair.Value);
            }
        }
示例#2
0
        private T SerializeThenDeserialize <T>(T input)
        {
            Serializer serializer = new Serializer();
            TextWriter writer     = new StringWriter();

            serializer.Serialize(writer, input, typeof(T));

            string serialized = writer.ToString();

            Console.WriteLine("serialized =\n-----\n{0}", serialized);

            return(YamlSerializer.Create(input).Deserialize(new StringReader(serialized)));
        }