예제 #1
0
        public void Load(Stream s)
        {
            IniSection currentSection = null;

            foreach (var line in s.ReadAllLines())
            {
                if (line.Length == 0)
                {
                    continue;
                }

                switch (line[0])
                {
                case ';': break;

                case '[': currentSection = ProcessSection(line); break;

                default: ProcessEntry(line, currentSection); break;
                }
            }
        }
예제 #2
0
        static bool ProcessEntry(string line, IniSection currentSection)
        {
            var comment = line.IndexOf(';');

            if (comment >= 0)
            {
                line = line.Substring(0, comment);
            }

            line = line.Trim();
            if (line.Length == 0)
            {
                return(false);
            }

            var key   = line;
            var value = "";
            var eq    = line.IndexOf('=');

            if (eq >= 0)
            {
                key   = line.Substring(0, eq).Trim();
                value = line.Substring(eq + 1, line.Length - eq - 1).Trim();
            }

            if (currentSection == null)
            {
                throw new InvalidOperationException("No current INI section");
            }

            if (!currentSection.Contains(key))
            {
                currentSection.Add(key, value);
            }
            return(true);
        }
예제 #3
0
        public void Load(Stream s)
        {
            var        reader         = new StreamReader(s);
            IniSection currentSection = null;

            while (!reader.EndOfStream)
            {
                var line = reader.ReadLine();

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

                switch (line[0])
                {
                case ';': break;

                case '[': currentSection = ProcessSection(line); break;

                default: ProcessEntry(line, currentSection); break;
                }
            }
        }