Пример #1
0
        void ParseFile()
        {
            _lineNumber = 0;
            String sectionName = null;

            _elements = new IniFileIndex();

            IniFileSection currentSection = null;

            foreach (String l in File.ReadAllLines(FileName))
            {
                _lineNumber++;

                String line = l.Trim();
                if (line.Length == 0)
                {
                    continue;
                }

                String key, value;

                if (line.StartsWith("["))
                {
                    sectionName    = GetSectionName(line);
                    currentSection = new IniFileSection(sectionName, _lineNumber);
                    _elements.Add(currentSection);
                }
                else if (TryGetElement(line, out key, out value))
                {
                    if (currentSection == null)
                    {
                        throw new IniFileException("Element found outside of a section on line {0}", _lineNumber);
                    }

                    if (currentSection.Elements.ContainsKey(key))
                    {
                        throw new IniFileException("Duplicate key found on line {0}", _lineNumber);
                    }

                    currentSection.Elements.Add(key, value);
                }
            }
        }
Пример #2
0
 protected IniFile(String fileName)
 {
     FileName  = fileName;
     _elements = new IniFileIndex();
     ParseFile();
 }