// public TomeArray(JArray data, JToken root) { // this.root = root; if (this.root == null) { this.root = this; } // for (var i = 0; i < data.Count; i += 1) { Add(Tome.Conjure(data[i], this.root)); } // OnChanged += EmitToParents; OnAdd += EmitChanged; OnDel += EmitChanged; }
// public TomeObject(JObject data, JToken root) { // this.root = root; if (this.root == null) { this.root = this; } // foreach (JProperty property in data.Properties()) { Add(property.Name, Tome.Conjure(property.Value, this.root)); } // OnChanged += EmitToParents; OnAdd += EmitChanged; OnDel += EmitChanged; }
// public void Destroy() { lock ((object)this) { foreach (JToken value in this) { Tome.Destroy(value); } if (OnDestroy != null) { OnDestroy.Invoke(); } OnChanged = null; OnDestroy = null; OnAdd = null; OnDel = null; } }
// public void Destroy() { lock ((object)this) { foreach (KeyValuePair <string, JToken> property in this) { Tome.Destroy(property.Value); } if (OnDestroy != null) { OnDestroy.Invoke(); } OnChanged = null; OnDestroy = null; OnAdd = null; OnDel = null; } }
// public void Assign(JToken newValue) { lock ((object)this) { switch (newValue.Type) { case JTokenType.Array: var newTomeArray = new TomeArray((JArray)newValue, root); Replace(newTomeArray); if (Parent == null) { // If replace was successfuly move over event handlers and call new OnChanged handler // The instance in which replace would not be successful, is when the old and new values are the same OnChanged -= EmitToParents; OnChanged += newTomeArray.OnChanged; newTomeArray.OnChanged = OnChanged; newTomeArray.OnDestroy = OnDestroy; OnAdd -= EmitChanged; OnAdd += newTomeArray.OnAdd; newTomeArray.OnAdd = OnAdd; OnDel -= EmitChanged; OnDel += newTomeArray.OnDel; newTomeArray.OnDel = OnDel; if (newTomeArray.OnChanged != null) { newTomeArray.OnChanged.Invoke(null); } } else { // Otherwise call original OnChanged handler if (OnChanged != null) { OnChanged.Invoke(null); } } break; case JTokenType.Object: var newTomeObject = new TomeObject((JObject)newValue, root); Replace(newTomeObject); if (Parent == null) { // If replace was successfuly move over event handlers and call new OnChanged handler // The instance in which replace would not be successful, is when the old and new values are the same OnChanged -= EmitToParents; OnChanged += newTomeObject.OnChanged; newTomeObject.OnChanged = OnChanged; newTomeObject.OnDestroy = OnDestroy; OnAdd -= EmitChanged; OnAdd += newTomeObject.OnAdd; newTomeObject.OnAdd = OnAdd; OnDel -= EmitChanged; OnDel += newTomeObject.OnDel; newTomeObject.OnDel = OnDel; if (newTomeObject.OnChanged != null) { newTomeObject.OnChanged.Invoke(null); } } else { // Otherwise call original OnChanged handler if (OnChanged != null) { OnChanged.Invoke(null); } } break; default: var newTomeValue = new TomeValue((JValue)newValue, root); Replace(newTomeValue); if (Parent == null) { // If replace was successfuly move over event handlers and call new OnChanged handler // The instance in which replace would not be successful, is when the old and new values are the same OnChanged -= EmitToParents; OnChanged += newTomeValue.OnChanged; newTomeValue.OnChanged = OnChanged; newTomeValue.OnDestroy = OnDestroy; if (newTomeValue.OnChanged != null) { newTomeValue.OnChanged.Invoke(null); } } else { // Otherwise call original OnChanged handler if (OnChanged != null) { OnChanged.Invoke(null); } } break; } } }