// public void ApplyOperation(string op, JToken val, JToken root) { lock ((object)this) { switch (op) { case "assign": Assign(val); break; case "set": Set((string)val["key"], val["val"]); break; case "del": Del((string)val); break; case "move": var fromKey = (string)val["key"]; JToken toParent = Tome.PathValue(root, val["newParent"] as JArray); JToken toKey = (val["newKey"] != null) ? val["newKey"] : new JValue(fromKey); Move(fromKey, toParent, toKey); break; case "rename": foreach (KeyValuePair <string, JToken> property in (JObject)val) { string wasKey = property.Key; var isKey = (string)property.Value; Rename(wasKey, isKey); } break; case "swap": var firstKey = (string)val["key"]; JToken secondParent = Tome.PathValue(root, val["newParent"] as JArray); JToken secondKey = (val["newKey"] != null) ? val["newKey"] : new JValue(firstKey); Swap(firstKey, secondParent, secondKey); break; default: throw new Exception("TomeObject - Unsupported operation: " + op); } } }
// public void ApplyOperation(string op, JToken val, JToken root) { lock ((object)this) { switch (op) { case "assign": Assign(val); break; case "set": Set((int)val["key"], val["val"]); break; case "del": Del((int)val); break; case "move": var fromKey = (int)val["key"]; JToken newParent = Tome.PathValue(root, val["newParent"] as JArray); JToken toKey = (val["newKey"] != null) ? val["newKey"] : new JValue(fromKey); Move(fromKey, newParent, toKey); break; case "rename": foreach (KeyValuePair <string, JToken> property in (JObject)val) { int wasKey = int.Parse(property.Key); var isKey = (int)property.Value; Rename(wasKey, isKey); } break; case "swap": var firstKey = (int)val["key"]; JToken secondParent = Tome.PathValue(root, val["newParent"] as JArray); JToken secondKey = (val["newKey"] != null) ? val["newKey"] : new JValue(firstKey); Swap(firstKey, secondParent, secondKey); break; case "push": foreach (JToken item in (JArray)val) { Push(item); } break; case "pop": Pop(); break; case "shift": Shift(); break; case "unshift": var unshiftItems = val as JArray; for (int i = unshiftItems.Count; i > 0; i -= 1) { UnShift(unshiftItems[i - 1]); } break; case "reverse": Reverse(); break; case "splice": var index = (int)val[0]; var deleteCount = (int)val[1]; var items = new JArray(val as JArray); items.First.Remove(); items.First.Remove(); Splice(index, deleteCount, items); break; default: throw new Exception("TomeArray - Unsupported operation: " + op); } } }