Exemple #1
0
 public IniFileSection this[string sectionName]
 {
     get
     {
         IniFileSection section = getSection(sectionName);
         if (section != null)
         {
             return(section);
         }
         IniFileSectionStart iniFileSectionStart;
         if (sections.Count > 0)
         {
             IniFileSectionStart sectionStart = sections[sections.Count - 1].sectionStart;
             iniFileSectionStart = sectionStart.CreateNew(sectionName);
         }
         else
         {
             iniFileSectionStart = IniFileSectionStart.FromName(sectionName);
         }
         elements.Add(iniFileSectionStart);
         section = new IniFileSection(this, iniFileSectionStart);
         sections.Add(section);
         return(section);
     }
 }
Exemple #2
0
        public static IniFile FromElements(IEnumerable <IniFileElement> elemes)
        {
            IniFile iniFile = new IniFile();

            iniFile.elements.AddRange(elemes);
            if (iniFile.elements.Count > 0)
            {
                IniFileSection iniFileSection = null;
                if (iniFile.elements[iniFile.elements.Count - 1] is IniFileBlankLine)
                {
                    iniFile.elements.RemoveAt(iniFile.elements.Count - 1);
                }
                for (int i = 0; i < iniFile.elements.Count; i++)
                {
                    IniFileElement iniFileElement = iniFile.elements[i];
                    if (iniFileElement is IniFileSectionStart)
                    {
                        iniFileSection = new IniFileSection(iniFile, (IniFileSectionStart)iniFileElement);
                        iniFile.sections.Add(iniFileSection);
                    }
                    else if (iniFileSection != null)
                    {
                        iniFileSection.elements.Add(iniFileElement);
                    }
                    else if (iniFile.sections.Exists((IniFileSection a) => a.Name == ""))
                    {
                        iniFile.sections[0].elements.Add(iniFileElement);
                    }
                    else if (iniFileElement is IniFileValue)
                    {
                        iniFileSection = new IniFileSection(iniFile, IniFileSectionStart.FromName(""));
                        iniFileSection.elements.Add(iniFileElement);
                        iniFile.sections.Add(iniFileSection);
                    }
                }
            }
            return(iniFile);
        }