using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;

namespace DataContracts
{
    class Program
    {
        static void Main(string[] args)
        {
            // Listing 16-24
            var bart = new Person { Name = "Bartek" };
            var millhouse = new Person { Name = "Milewski" };
            var ralph = new Person { Name = "Rafał" };
            var wigglePuppy = new Person { Name = "szczeniaczek" };

            bart.Friends.Add(millhouse);
            bart.Friends.Add(ralph);
            ralph.Friends.Add(wigglePuppy);

            MemoryStream stream = new MemoryStream();
            var serializer = new DataContractSerializer(typeof(Person));
            serializer.WriteObject(stream, bart);

            stream.Seek(0, SeekOrigin.Begin);
            string content = new StreamReader(stream).ReadToEnd();
            Console.WriteLine(content);
        }
    }
}
