Пример #1
0
        private void Handle(LinePeeker peeker)
        {
            var line   = peeker.PeekLine() ?? string.Empty;
            var method = LineAnalyzers.FirstOrDefault(a => a.Key(line));

            if (method.Key == null || method.Value == null)
            {
                throw new InvalidOperationException();
            }

            var childInis = _children.OfType <IniFile>().ToArray();
            var ini       = childInis.Any() ? childInis.Last() : this;

            method.Value(ini, peeker);
        }
Пример #2
0
        public static IniFile Parse(string content)
        {
            var ini = new IniFile();

            using (var reader = new StringReader(content))
            {
                var peeker = new LinePeeker(reader);

                while (reader.Peek() >= 0)
                {
                    ini.Handle(peeker);
                }
            }

            return(ini);
        }