public void OnObjectStart(string name) { var state = new KVPartialState(); state.Key = name; StateStack.Push(state); }
static void Merge(KVPartialState from, KVPartialState into) { foreach (var item in from.Items) { var matchingItem = into.Items.FirstOrDefault(i => i.Name == item.Name); if (matchingItem == null) { into.Items.Add(item); } else { Merge(from: item, into: matchingItem); } } }
public void OnKeyValuePair(string name, KVValue value) { if (StateStack.Count > 0) { var state = StateStack.Peek(); state.Items.Add(new KVObject(name, value)); } else { var state = new KVPartialState(); state.Key = name; state.Value = value; StateStack.Push(state); } }
KVObject MakeObject(KVPartialState state) { if (state.Discard) { return(null); } KVObject @object; if (state.Value != null) { @object = new KVObject(state.Key, state.Value); } else { @object = new KVObject(state.Key, state.Items); } return(@object); }