internal Task SaveAsync() { string json; lock (Mutex) json = JsonProcessor.Encode(InternalDictionary); return(File.WriteToAsync(json)); }
/// <summary> /// Parses a JSON-text as defined in http://tools.ietf.org/html/rfc4627, returning an /// IDictionary<string, object> or an IList<object> depending on whether /// the value was an array or dictionary. Nested objects also match these types. /// </summary> public static object Parse(string input) { input = input.Trim(); JsonProcessor parser = new JsonProcessor(input); if ((parser.ParseObject(out object output) || parser.ParseArray(out output)) && parser.CurrentIndex == input.Length) { return(output); } throw new ArgumentException("Input JSON was invalid."); }
internal Task LoadAsync() => File.ReadAllTextAsync().ContinueWith(t => { string text = t.Result; Dictionary <string, object> result = null; try { result = JsonProcessor.Parse(text) as Dictionary <string, object>; } catch (Exception) { } lock (Mutex) InternalDictionary = result ?? new Dictionary <string, object> { }; });