Ejemplo n.º 1
0
        private ConfigSection FindOrCreateConfigSection(string name)
        {
            ConfigSection configSectionToFind = new ConfigSection(name);

            foreach (ConfigSection configSection in sections)
            {
                if (configSection.SectionName == configSectionToFind.SectionName &&
                    configSection.SubSection == configSectionToFind.SubSection)
                    return configSection;
            }
            sections.Add(configSectionToFind);
            return configSectionToFind;
        }
Ejemplo n.º 2
0
        private void Load()
        {
            if (!File.Exists(fileName))
                return;

            string[] fileLines = File.ReadAllLines(fileName, Settings.Encoding);

            ConfigSection configSection = null;

            foreach (string line in fileLines)
            {
                Match m = regParseIsSection.Match(line);
                if (m.Success) //this line is a section
                {
                    string name = m.Groups["SectionName"].Value;

                    configSection = new ConfigSection(name);
                    this.sections.Add(configSection);
                }
                else
                {
                    m = regParseIsKey.Match(line);
                    if (m.Success) //this line is a key
                    {
                        string key = m.Groups["Key"].Value;
                        string value = unescapeString(m.Groups["Value"].Value);

                        if (configSection == null)
                            throw new Exception("Key " + key + " in configfile " + fileName + " is not in a section.");

                        configSection.SetValue(key, value);
                    }
                }

            }
        }
Ejemplo n.º 3
0
        private ConfigSection FindConfigSection(string name)
        {
            ConfigSection configSectionToFind = new ConfigSection(name);

            foreach (ConfigSection configSection in sections)
            {
                if (configSection.SectionName == configSectionToFind.SectionName &&
                    configSection.SubSection == configSectionToFind.SubSection)
                    return configSection;
            }
            return null;
        }