Exemplo n.º 1
0
        public void SetValue(string key, string value)
        {
            IniLine line = FindLine(key);

            if (ReferenceEquals(line, null))
            {
                line = new IniLine(key, value);
                Add(line);
            }
            else
            {
                line.Value = value;
            }
        }
Exemplo n.º 2
0
 public string this[string key]
 {
     get
     {
         IniLine line = FindLine(key);
         return(ReferenceEquals(line, null)
             ? string.Empty
             : line.Value);
     }
     set
     {
         SetValue(key, value);
     }
 }
Exemplo n.º 3
0
        public string GetValue(string sectionName,
                               string key, string defaultValue)
        {
            IniSection section = GetSection(sectionName);

            if (ReferenceEquals(section, null))
            {
                return(defaultValue);
            }
            IniLine line = section.FindLine(key);

            if (ReferenceEquals(line, null))
            {
                return(defaultValue);
            }
            return(line.Value);
        }
Exemplo n.º 4
0
        public static IniFile Parse(string[] lines)
        {
            IniFile    result  = new IniFile();
            IniSection section = null;

            char[] delimiters = { '=' };
            foreach (string line in lines)
            {
                string text = line.Trim();
                if (Utility.IsNullOrEmpty(text))
                {
                    continue;
                }
                if (text.StartsWith("["))
                {
                    text         = text.Trim('[', ']');
                    section      = new IniSection();
                    section.Name = text;
                    result.Add(section);
                }
                else
                {
                    string[] parts = text.Split(delimiters, 2);
                    string   key   = parts[0];
                    string   value = parts.Length == 2
                        ? parts[1]
                        : string.Empty;
                    IniLine item = new IniLine(key, value);
                    if (!ReferenceEquals(section, null))
                    {
                        section.Add(item);
                    }
                }
            }

            return(result);
        }
Exemplo n.º 5
0
 public void Add(IniLine line)
 {
     _lines.Add(line);
 }