Esempio n. 1
0
        /// <summary>
        /// 逐行解析 Ini 配置文件字符串
        /// </summary>
        /// <param name="textReader"></param>
        /// <returns></returns>
        private static IniObject ParseIni(TextReader textReader)
        {
            IniObject iniObj = new IniObject();
            string    key    = string.Empty;

            while (textReader.Peek() != -1)
            {
                string line = textReader.ReadLine();
                if (!string.IsNullOrEmpty(line))                      //跳过空行
                {
                    for (int i = 0; i < Regices.Length; i++)
                    {
                        Match match = Regices[i].Match(line);
                        if (match.Success)
                        {
                            if (i == 0)
                            {
                                key = match.Groups[1].Value;
                                iniObj.Add(new IniSection(key));
                                break;
                            }
                            else if (i == 1)
                            {
                                iniObj[key].Add(match.Groups[1].Value.Trim(), match.Groups[2].Value);
                            }
                        }
                    }
                }
            }
            return(iniObj);
        }