private static void Main() { XmlSerializer serializer = new XmlSerializer(typeof(SongGroup)); SongGroup group = new SongGroup(); group.Songs.Add(new Song() { Artist = "A1", SongTitle = "S1" }); group.Songs.Add(new Song() { Artist = "A2", SongTitle = "S2" }); using (Stream stream = new MemoryStream()) using (StreamWriter writer = new StreamWriter(stream)) { serializer.Serialize(writer, group); stream.Seek(0, SeekOrigin.Begin); using (StreamReader reader = new StreamReader(stream)) { Console.WriteLine(reader.ReadToEnd()); } } }
public static void CompositeTwoOrMusicGenerator() { SongComponent industrialMusic = new SongGroup("Industrial", "Some industial music"); SongComponent heavyMetalMusic = new SongGroup("Heavy Metal Music", "Some Heavy Metal Music"); SongComponent everySong = new SongGroup("Song list", "Every Song Available"); everySong.Add(industrialMusic); industrialMusic.Add(new Song("Some Hit", "LALA", 1990)); industrialMusic.Add(new Song("Some other Hit", "LOLO", 1990)); industrialMusic.Add(heavyMetalMusic); heavyMetalMusic.Add(new Song("Hard Rock Aliluia", "Hard", 1980)); heavyMetalMusic.Add(new Song("Hard Rock Aliluia 2", "Hard2", 1981)); DiskJokey crazyKostas = new DiskJokey(everySong); crazyKostas.GetSongList(); }