protected JDict GetDict(string key, bool reseteable = false, int capacity = 0, bool subscribeToChildren = true) { if (!initialized) { this[key] = new JDict(reseteable, capacity, subscribeToChildren); } return(this[key].AsDict()); }
public override JNode Clone() { var newDict = new JDict(reseteable, dictionary.Count, subscribeToChildren); foreach (var kvp in dictionary) { newDict.Add(kvp.Key, kvp.Value.Clone()); } return(newDict); }
private static JNode Process(JsonValue value) { JNode result; switch (value.JsonType) { case JsonType.Object: var jsonObject = value.Qo(); var dict = new JDict(false, jsonObject.Count, true); result = dict; foreach (var kvp in jsonObject) { dict.Add(kvp.Key, Process(kvp.Value)); } break; case JsonType.Array: var jsonArray = value.Qa(); var list = new JList(true, jsonArray.Count, true); result = list; foreach (var item in jsonArray) { list.Add(Process(item)); } break; case JsonType.Boolean: result = new JData <bool>(value.Qb(), default(bool)); break; case JsonType.Number: var valueType = value.ToValue().GetType(); if (valueType == typeof(int)) { result = new JData <int>(value.Qi(), default(int)); } else if (valueType == typeof(long)) { result = new JData <long>(value.Ql(), default(long)); } else if (valueType == typeof(float)) { result = new JData <float>((float)value.Qd(), default(float)); } else if (valueType == typeof(double)) { result = new JData <double>(value.Qd(), default(double)); } else { throw new Exception($"JsonValue of type Number contains an invalid type of: {valueType.GetFriendlyName()}."); } break; case JsonType.String: // TODO: Try to detect types and convert result = new JData <string>(value.Qs(), default(string)); break; case JsonType.Unknown: default: result = new JData <string>(value.Qstr(), default(string)); break; } return(result); }