public static Models.WordList ConvertToObject(WordListXml wordListXml) { var words = new List<Word>(); foreach (WordXml wordXml in wordListXml.Words) { words.Add(ConvertToObject(wordXml)); } var wordList = new Models.WordList(); wordList.Populate(words); return wordList; }
public static WordListXml ConvertToXml(Models.WordList wordList) { var wordListXml = new WordListXml(); List<Word> words = wordList.GetAllWords().Select(w => w.Word).ToList(); wordListXml.Words = new WordXml[words.Count]; int idx = 0; foreach (Word word in words) { wordListXml.Words[idx++] = ConvertToXml(word); } return wordListXml; }
public void GenerateXml(Models.WordList wordList, Stream outputStream) { WordList.WordListXml wordsXml = WordListXmlConverter.ConvertToXml(wordList); XmlWriterSettings xmlWriterSettings = new XmlWriterSettings(); xmlWriterSettings.Encoding = new UTF8Encoding(false); xmlWriterSettings.Indent = true; using (XmlWriter writer = XmlWriter.Create(outputStream, xmlWriterSettings)) { serializer.Serialize(writer, wordsXml); writer.Flush(); } }