public bool Open(Stream stream) { if (stream == null) { return(false); } sections = new Dictionary <string, ConfigSection>(); order = new List <ConfigSection>(); ConfigSectionTemplate currentTemplate = new ConfigSectionTemplate(); List <ConfigLineTemplate> lines = new List <ConfigLineTemplate>(); StreamReader reader = new StreamReader(stream); String line; while (null != (line = reader.ReadLine())) { ConfigLineTemplate templateLine = new ConfigLineTemplate(line); //if (templateLine.Type == ConfigLineType.Invalid) // return false; if (templateLine.Type != ConfigLineType.Section) { currentTemplate.Lines.Add(templateLine); } else { if (sections.ContainsKey(currentTemplate.Name.ToLower())) { return(false); } ConfigSection current = new ConfigSection(); if (!current.Open(currentTemplate)) { return(false); } sections.Add(currentTemplate.Name.ToLower(), current); order.Add(current); currentTemplate = new ConfigSectionTemplate(); currentTemplate.Lines.Add(templateLine); } } if (sections.ContainsKey(currentTemplate.Name.ToLower())) { return(false); } ConfigSection last = new ConfigSection(); if (!last.Open(currentTemplate)) { return(false); } sections.Add(currentTemplate.Name.ToLower(), last); order.Add(last); stream.Close(); return(true); }
internal bool Open(ConfigSectionTemplate template) { this.template = template; values = new Dictionary <string, string>(); foreach (ConfigLineTemplate line in template.Lines) { if (line.Type == ConfigLineType.Key) { if (values.ContainsKey(line.Key.ToLower())) { // if the key is already read, read this one as a next line values[line.Key.ToLower()] += "\n" + line.Value; } else { values.Add(line.Key.ToLower(), line.Value); } } } return(true); }