// private void EmitChanged(JToken key) { if (OnChanged != null) { OnChanged.Invoke(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; 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; 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; } } }