static void Main(string[] args) { var projectPath = Path.GetDirectoryName(Path.GetDirectoryName(System.IO.Directory.GetCurrentDirectory())); string path = Path.Combine(projectPath, "Config.txt"); var config = new TxtReader(path); Console.WriteLine(config["id"]); Console.WriteLine(config["session"]["timeout"]); Console.WriteLine(config["session"]["server"]["1"]["port"]); Console.WriteLine(config["image"]["cat"]["width"]); Console.WriteLine(config["image"]["folder"]); Console.ReadKey(); }
public TxtReader Add(string name, string value, TxtReader parent) { var existingElement = AllItems.Where(x => x.Name == name && x.Parent == parent).SingleOrDefault(); if (existingElement != null) { return(existingElement); } else { TxtReader newItem = new TxtReader(name, value, parent); Items.Add(newItem); AllItems.Add(newItem); return(newItem); } }
public void ParseFile() { try { var lines = File.ReadAllLines(Path); foreach (var line in lines) { TxtReader parent = null; var splittedLines = line.Split('='); var leftLines = splittedLines[0].Split('.'); for (int i = 0; i < leftLines.Length; i++) { parent = Add(leftLines[i], i != leftLines.Length - 1 ? String.Empty : splittedLines[1], parent); } } } catch (Exception ex) { throw ex; } }
public TxtReader(string name, string value, TxtReader parent) { Name = name; Value = value; Parent = parent; }