/// <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); } }
/// <summary>Reads a INI file from a stream.</summary> public static IniFileEx FromStream(StreamReader reader) { IEnumerable <IniFileElement> elemes = ParseText(reader); IniFileEx ret = new IniFileEx(); ret.elements.AddRange(elemes); if (ret.elements.Count > 0) { IniFileSection section = null; 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++) { IniFileElement 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); }