private PSO2ConfigToken selectRecursive(IEnumerable <string> path) { PSO2ConfigToken result = null; foreach (string smallpath in path) { if (result != null) { result = result[smallpath] as PSO2ConfigToken; } else { result = this[smallpath]; } } return(result); }
protected void ReadFromFile(string filepath) { using (StreamReader sr = new StreamReader(filepath)) { this.Clear(); List <string> r_currentPath = new List <string>(); string bufferedProperty = null, bufferedValue = null; char[] charBuffer = new char[2]; PSO2ConfigToken token = null; StringBuilder bufferingText = new StringBuilder(); int readCount = sr.ReadBlock(charBuffer, 0, 1); while (readCount > 0) { switch (charBuffer[0]) { case '\0': break; case '\n': break; case '\r': break; case '=': bufferedProperty = bufferingText.ToString(); if (!string.IsNullOrEmpty(bufferedProperty)) { bufferedProperty = bufferedProperty.Trim(); } bufferingText.Clear(); break; case '{': if (bufferedProperty != null) { r_currentPath.Add(bufferedProperty); token = selectRecursive(r_currentPath); bufferedProperty = null; bufferingText.Clear(); } break; case '}': r_currentPath.RemoveAt(r_currentPath.Count - 1); token = selectRecursive(r_currentPath); break; case ',': if (bufferedProperty != null) { bufferedValue = bufferingText.ToString(); if (!string.IsNullOrEmpty(bufferedValue)) { bufferedValue = bufferedValue.Trim(); } token.Values[bufferedProperty] = bufferedValue; bufferingText.Clear(); bufferedProperty = null; bufferedValue = null; } break; default: bufferingText.Append(charBuffer, 0, readCount); break; } readCount = sr.ReadBlock(charBuffer, 0, 1); } } }