Esempio n. 1
0
        public void LoadFile(string path)
        {
            if (!File.Exists(path))
            {
                throw new FileNotFoundException("Unable to locate " + path);
            }
            filepath = path;
            StreamReader reader = new StreamReader(path);
            string       line;
            string       currentSection = null;

            while (!reader.EndOfStream)
            {
                LineEntry lineEntry = new LineEntry();
                line = reader.ReadLine().Trim();
                if (line.Length == 0)
                {
                    lineEntry.type = LineType.empty;
                }
                else if (IsComment(line))
                {
                    lineEntry.type    = LineType.comment;
                    lineEntry.comment = line;
                }
                else if (IsSectionName(line))
                {
                    lineEntry.type    = LineType.section;
                    lineEntry.section = line.Substring(1, line.Length - 2);
                    currentSection    = lineEntry.section;
                }
                else if (IsParameterDefinition(line))
                {
                    int    offset = line.IndexOf("=");
                    string value  = null;
                    if (line.Length > offset + 1)
                    {
                        value = line.Substring(offset + 1).Trim();
                    }

                    lineEntry.type      = LineType.parameter;
                    lineEntry.section   = currentSection;
                    lineEntry.parameter = line.Substring(0, offset).Trim();
                    lineEntry.value     = value;
                }
                lines.Add(lineEntry);
            }
            reader.Close();
        }
Esempio n. 2
0
        public void AddParameter(string ParameterName, string Value = null, string SectionName = null)
        {
            if (!SectionExists(SectionName))
            {
                return;
            }
            if (ParameterExists(ParameterName, SectionName))
            {
                return;
            }
            LineEntry le = new LineEntry();

            le.type      = LineType.parameter;
            le.section   = SectionName;
            le.parameter = ParameterName;
            le.value     = Value;
            lines.Insert(getIndexForNewParameter(SectionName), le);
        }
Esempio n. 3
0
        public string GetParameterValue(string ParameterName, string SectionName)
        {
            LineEntry le = lines.Find(x => x.section == SectionName && x.parameter == ParameterName);

            return(le.value);
        }