Exemple #1
0
        /// <summary>
        /// Constructor, call it with the .ini to parse
        /// </summary>
        /// <param name="file"></param>
        public IniReader(string file)
        {
            var currentSection = new Dictionary <string, string>(StringComparer.InvariantCultureIgnoreCase);

            if (!File.Exists(file))
            {
                return;
            }
            _ini[""] = currentSection;
            Utils.ForEachLine(file, null, (i, line) => {
                line = line.Trim();
                if (line.StartsWith(";"))
                {
                    return;
                }
                if (line.StartsWith("[") && line.EndsWith("]"))
                {
                    currentSection = new Dictionary <string, string>(StringComparer.InvariantCultureIgnoreCase);
                    _ini[line.Substring(1, line.LastIndexOf("]", StringComparison.CurrentCultureIgnoreCase) - 1)] = currentSection;
                    return;
                }
                var idx = line.IndexOf("=", StringComparison.CurrentCultureIgnoreCase);
                if (idx == -1)
                {
                    currentSection[line] = "";
                }
                else
                {
                    currentSection[line.Substring(0, idx)] = line.Substring(idx + 1);
                }
            });
        }