public static Ini FromElements(IEnumerable <IniElement> elemes) { var ret = new Ini(); ret.Elements.AddRange(elemes); if (ret.Elements.Count > 0) { IniSection section = null; if (ret.Elements[ret.Elements.Count - 1] is IniBlankLine) { ret.Elements.RemoveAt(ret.Elements.Count - 1); } foreach (var element in ret.Elements) { var el = element; if (el is IniSectionStart) { section = new IniSection(ret, (IniSectionStart)el); ret.Sections.Add(section); } else if (section != null) { section.Elements.Add(el); } else if (ret.Sections.Exists(a => a.Name == "")) { ret.Sections[0].Elements.Add(el); } else if (el is IniValue) { section = new IniSection(ret, IniSectionStart.FromName("")); section.Elements.Add(el); ret.Sections.Add(section); } } } return(ret); }
public static Ini FromElements(IEnumerable<IniElement> elemes) { var ret = new Ini(); ret.Elements.AddRange(elemes); if (ret.Elements.Count > 0) { IniSection section = null; if (ret.Elements[ret.Elements.Count - 1] is IniBlankLine) ret.Elements.RemoveAt(ret.Elements.Count - 1); foreach (var element in ret.Elements) { var el = element; if (el is IniSectionStart) { section = new IniSection(ret, (IniSectionStart)el); ret.Sections.Add(section); } else if (section != null) section.Elements.Add(el); else if (ret.Sections.Exists(a => a.Name == "")) ret.Sections[0].Elements.Add(el); else if (el is IniValue) { section = new IniSection(ret, IniSectionStart.FromName("")); section.Elements.Add(el); ret.Sections.Add(section); } } } return ret; }
public IniSection this[string sectionName] { get { var sect = GetSection(sectionName); if (sect != null) return sect; IniSectionStart start; if (Sections.Count > 0) { var prev = Sections[Sections.Count - 1].SectionStart; start = prev.CreateNew(sectionName); } else start = IniSectionStart.FromName(sectionName); if (IniSettings.SeparateSection) { Elements.Add(new IniBlankLine(1)); } Elements.Add(start); sect = new IniSection(this, start); Sections.Add(sect); return sect; } }
public void WriteSection(IniSection section) { WriteElement(section.SectionStart); for (var i = section.Parent.Elements.IndexOf(section.SectionStart) + 1; i < section.Parent.Elements.Count; i++) { if (section.Parent.Elements[i] is IniSectionStart) break; WriteElement(section.Parent.Elements[i]); } }