Esempio n. 1
0
        static void ReadFromEntry(XmlReader reader, ReadableEntry currentEntryLevel, string currentEntryName, string nextEntry = "")
        {
            string elementName  = nextEntry;
            string currentValue = "";



            while (reader.Read())
            {
                switch (reader.NodeType)
                {
                case XmlNodeType.Element:
                    //If a previous element does exist, then that suggests that we are in a subentry. Make a new subentry and parse.
                    if (elementName != "")
                    {
                        //Check to see how many entries there are

                        //Find if the namespace indicates that this is part of a subentry array

                        currentEntryLevel.AddEntryReadableEntry(elementName, new ReadableEntry());
                        ReadFromEntry(reader, currentEntryLevel.SubEntries[elementName].Last(), elementName, reader.Name);
                    }
                    elementName = reader.Name;
                    break;

                case XmlNodeType.Text:
                    currentValue = reader.Value;
                    break;

                case XmlNodeType.EndElement:
                    //This suggests that there was a value to be read between element tags. Add the entry now.
                    if (currentValue != "")
                    {
                        currentEntryLevel.AddEntrySingle(reader.Name, currentValue, true);
                    }
                    //If there was no value read and the end element name matches the start element, then it must signal the end of the entry
                    else if (reader.Name == currentEntryName)
                    {
                        return;
                    }
                    //Reset the current value and element name
                    currentValue = "";
                    elementName  = "";
                    break;
                }
            }
        }
Esempio n. 2
0
 public void GetEntry <T>(string name, out T value)
     where T : IReadableFormatter, new()
 {
     if (!readableObjEntries.ContainsKey(name))
     {
         value = default(T);
     }
     else if (readableObjEntries[name] == null)
     {
         value = default(T);
     }
     else
     {
         ReadableEntry entry = readableObjEntries[name][0];
         value = new T();
         value.FromReadableFormat(entry);
     }
 }
Esempio n. 3
0
        public static void ToXML(IReadableFormatter obj, string filename)
        {
            XmlWriterSettings settings = new XmlWriterSettings();

            settings.Indent      = true;
            settings.IndentChars = ("\t");

            using (XmlWriter writer = XmlWriter.Create(filename, settings))
            {
                writer.WriteStartDocument();

                ReadableEntry entry = obj.ToReadableFormat();

                WriteXMLEntry(entry, writer, System.IO.Path.GetFileNameWithoutExtension(filename));

                writer.WriteEndDocument();
            }
        }