Пример #1
0
 /// <summary>Writes a section to a file</summary>
 /// <param name="section">Section to write.</param>
 public void WriteSection(IniFileSection section)
 {
     WriteElement(section.sectionStart);
     for (int i = section.parent.elements.IndexOf(section.sectionStart) + 1; i < section.parent.elements.Count; i++)
     {
         if (section.parent.elements[i] is IniFileSectionStart)
             break;
         WriteElement(section.parent.elements[i]);
     }
 }
Пример #2
0
        /// <summary>Creates a new IniFile from elements collection (Advanced member).</summary>
        /// <param name="elemes">Elements collection.</param>
        public static IniFile FromElements(IEnumerable<IniFileElement> elemes)
        {
            IniFile ret = new IniFile();
            ret.elements.AddRange(elemes);
            if (ret.elements.Count > 0)
            {
                IniFileSection section = null;
                IniFileElement el;

                if (ret.elements[ret.elements.Count - 1] is IniFileBlankLine)
                    ret.elements.RemoveAt(ret.elements.Count - 1);
                for (int i = 0; i < ret.elements.Count; i++)
                {
                    el = ret.elements[i];
                    if (el is IniFileSectionStart)
                    {
                        section = new IniFileSection(ret, (IniFileSectionStart)el);
                        ret.sections.Add(section);
                    }
                    else if (section != null)
                        section.elements.Add(el);
                    else if (ret.sections.Exists(delegate(IniFileSection a) { return a.Name == ""; }))
                        ret.sections[0].elements.Add(el);
                    else if (el is IniFileValue)
                    {
                        section = new IniFileSection(ret, IniFileSectionStart.FromName(""));
                        section.elements.Add(el);
                        ret.sections.Add(section);
                    }
                }
            }
            return ret;
        }
Пример #3
0
 /// <summary>Gets a IniFileSection object from it's name</summary>
 /// <param name="sectionName">Name of section to search for. If not found, new one is created.</param>
 public IniFileSection this[string sectionName]
 {
     get
     {
         IniFileSection sect = getSection(sectionName);
         if (sect != null)
             return sect;
         IniFileSectionStart start;
         if (sections.Count > 0)
         {
             IniFileSectionStart prev = sections[sections.Count - 1].sectionStart;
             start = prev.CreateNew(sectionName);
         }
         else
             start = IniFileSectionStart.FromName(sectionName);
         elements.Add(start);
         sect = new IniFileSection(this, start);
         sections.Add(sect);
         return sect;
     }
 }