internal void AddSettings(String sectionName, IList<ConfigEntry> Entries) { ConfigSection section = configSections[sectionName]; if (section == null) { section = new ConfigSection(sectionName, configSections.Count); configSections.Add(sectionName, section); } foreach (ConfigEntry entry in Entries) { section.AddEntry((ConfigEntry)entry.Clone()); } }
/// <summary> /// Opens the INI file at the given path and enumerates the values in the IniParser. /// </summary> /// <param name="iniPath">Full path to INI file.</param> public INIFileParser(String iniPath) { configSections = new Dictionary<string, ConfigSection>(); TextReader iniFile = null; string strLine = null; ConfigSection currentSection = null; string[] keyValuePair = null; iniFilePath = iniPath; if (File.Exists(iniPath)) { try { iniFile = new StreamReader(iniPath); strLine = iniFile.ReadLine(); while (strLine != null) { strLine = strLine.Trim(); if (!string.IsNullOrEmpty(strLine)) { if (strLine.StartsWith("[") && strLine.EndsWith("]")) { currentSection = new ConfigSection(strLine.Substring(1, strLine.Length - 2), configSections.Count); configSections.Add(strLine.Substring(1, strLine.Length - 2), currentSection); } else { string key = null; String value = null; string commentString = GetLineCommentChars(strLine); keyValuePair = strLine.Split(new char[] { '=' }, 2); if (string.IsNullOrEmpty(commentString)) { key = keyValuePair[0]; } else { key = keyValuePair[0].Substring(commentString.Length, keyValuePair[0].Length - commentString.Length); } if (keyValuePair.Length > 1) { value = keyValuePair[1]; } currentSection.AddEntry(key, value, commentString); } } strLine = iniFile.ReadLine(); } } catch (Exception ex) { throw ex; } finally { if (iniFile != null) iniFile.Close(); } } else throw new FileNotFoundException("Unable to locate " + iniPath); }
public void CopyReplaceSection(String sourceSection, String destSectionName) { ConfigSection clone = new ConfigSection(configSections[sourceSection]); clone.OrderInFile = configSections[destSectionName].OrderInFile; clone.SectionName = configSections[destSectionName].SectionName; configSections.Remove(destSectionName); configSections.Add(destSectionName, clone); }
/// <summary> /// Adds or replaces a setting to the table to be saved. /// </summary> /// <param name="sectionName">Section to add under.</param> /// <param name="settingName">Key name to add.</param> /// <param name="settingValue">Value of key.</param> public void AddSetting(String sectionName, String settingName, String settingValue, string commentString) { ConfigSection section = configSections[sectionName]; if (section == null) { section = new ConfigSection(sectionName, configSections.Count); configSections.Add(sectionName, section); } section.AddEntry(settingName, settingValue, commentString); }
public ConfigSection(ConfigSection configSection) { SectionName = configSection.SectionName; OrderInFile = configSection.OrderInFile; Entries = new List <ConfigEntry>(configSection.Entries); }
public ConfigSection(ConfigSection configSection) { SectionName = configSection.SectionName; OrderInFile = configSection.OrderInFile; Entries = new List<ConfigEntry>(configSection.Entries); }