Beispiel #1
0
        /// <summary>
        /// 逐行解析 Ini 配置文件字符串
        /// </summary>
        /// <param name="textReader"></param>
        /// <returns></returns>
        private static IniObject ParseIni(TextReader textReader)
        {
            IniObject  iniObj  = new IniObject();
            IniSection iniSect = null;

            while (textReader.Peek() != -1)
            {
                string line = textReader.ReadLine();
                if (string.IsNullOrEmpty(line) == false && Regices[2].IsMatch(line) == false)                       //跳过空行和注释
                {
                    Match match = Regices[0].Match(line);
                    if (match.Success)
                    {
                        iniSect = new IniSection(match.Groups[1].Value);
                        iniObj.Add(iniSect);
                        continue;
                    }

                    match = Regices[1].Match(line);
                    if (match.Success)
                    {
                        iniSect.Add(match.Groups[1].Value.Trim(), match.Groups[2].Value);
                    }
                }
            }
            return(iniObj);
        }