public string Read(string key) { if (key == null || _jo == null) { return(null); } bool isLength = OptionPath.TryStripLength(key, out key); string path = "$." + key; JToken valueToken = _jo.SelectToken(path); if (isLength) { if (valueToken is JArray arrayToken) { return(arrayToken.Count.ToString()); } return(null); } return(GetStringValue(valueToken)); }
private string ReadYamlKey(string name) { if (name == null || !File.Exists(_fullName)) { return(null); } bool isLength = OptionPath.TryStripLength(name, out name); var ys = new YamlStream(); using (FileStream fs = File.OpenRead(_fullName)) using (var reader = new StreamReader(fs)) { ys = new YamlStream(); ys.Load(reader); } string[] parts = name.Split(HierarchySeparator, StringSplitOptions.RemoveEmptyEntries); YamlNode current = ys.Documents[0].RootNode; foreach (string part in parts) { current = DiveIn(current, part); if (current == null) { break; } } return(GetResult(current, isLength)); }