Ejemplo n.º 1
0
        public void Read()
        {
            IniSection curSection;

            curSection = new IniSection(null);
            _sections.Add(curSection);

            while(true) {
                var line = _in.ReadLine();
                if(line == null)
                    break;

                if(line.Length == 0 || line[0] == ';')
                    continue;

                if(line[0] == '[' && line[line.Length - 1] == ']') {
                    var name = line.Substring(1, line.Length - 2);
                    curSection = new IniSection(name);
                    _sections.Add(curSection);
                    continue;
                }

                var eqIndex = line.IndexOf('=');
                if(eqIndex == -1) {
                    curSection.Add(line, null);
                } else {
                    var key = line.Substring(0, eqIndex);
                    var value = line.Substring(eqIndex + 1);
                    curSection.Add(key, value);
                }
            }
        }
Ejemplo n.º 2
0
 int TryGetInt(IniSection section, string key, int def)
 {
     var str = section.GetValue(key);
     if(str == null)
         return def;
     int ret;
     if(!int.TryParse(str, out ret))
         return def;
     return ret;
 }
Ejemplo n.º 3
0
 bool TryGetBool(IniSection section, string key, bool def)
 {
     var str = section.GetValue(key);
     if(str == null)
         return def;
     return str.ToLower() == "yes";
 }