Beispiel #1
0
        private void WriteToXml(XmlSpellsLibrary library, XmlSerializer serializer)
        {
            XmlWriterSettings writerSettings = new XmlWriterSettings
            {
                NewLineHandling = NewLineHandling.Entitize
            };

            using (var writer = XmlWriter.Create(FilePath, writerSettings))
            {
                serializer.Serialize(writer, library);
            }
        }
Beispiel #2
0
        public void SaveSpell(BookSpell spell)
        {
            var serializer = new XmlSerializer(typeof(XmlSpellsLibrary));
            var library    = LoadSpellsLibrary(serializer);

            if (library == null)
            {
                library = new XmlSpellsLibrary();
                var path = Path.GetDirectoryName(FilePath);
                if (!string.IsNullOrEmpty(path))
                {
                    Directory.CreateDirectory(path);
                }
            }

            var resultSpells = new List <XmlBookSpell>(library.Spells ?? new XmlBookSpell[0])
            {
                new XmlBookSpell(spell)
            };

            library.Spells = resultSpells.ToArray();

            WriteToXml(library, serializer);
        }