/// <inheritdoc/> public bool Load(JProperty newProperty, bool reload = false) { Covenant.Requires <ArgumentNullException>(newProperty != null); var changed = !NeonHelper.JTokenEquals(property, newProperty); property = newProperty; if (property.Value == null || property.Value.Type == JTokenType.Null) { listWrapper = null; } else if (property.Value.Type == JTokenType.Array) { listWrapper = new EntityListWrapper <TEntity>(parentEntity, context, (JArray)property.Value, null); } else { listWrapper = null; } if (reload && changed) { parentEntity._OnPropertyChanged(PropertyName); } return(changed); }
/// <inheritdoc/> public bool Load(JProperty newProperty, bool reload = false) { Covenant.Requires <ArgumentNullException>(newProperty != null); var changed = !NeonHelper.JTokenEquals(property, newProperty); property = newProperty; if (newProperty.Value == null || newProperty.Value.Type == JTokenType.Null) { entityValue = null; } else if (newProperty.Value.Type == JTokenType.Object) { entityValue = DynamicEntity.Create <TEntity>(newProperty.Value as JObject, context); entityValue._Attach(parentEntity); } else { throw new InvalidCastException($"Unable to cast a [{newProperty.Type}] into a [{typeof(TEntity).FullName}]."); } if (reload && changed) { parentEntity._OnPropertyChanged(PropertyName); } return(changed); }
/// <summary> /// Called when the mapped <see cref="JObject"/> raises its property changed event. /// </summary> /// <param name="sender">The sender.</param> /// <param name="args">The arguments.</param> private void OnJsonPropertyChanged(object sender, PropertyChangedEventArgs args) { // Map the JSON property name to the equivalent entity property name // and then raise the entoty's property changed event. if (string.IsNullOrEmpty(args.PropertyName)) { // Relay null or empty property names. self._OnPropertyChanged(args.PropertyName); } else { string entityPropertyName; if (propertyNameMap.TryGetValue(args.PropertyName, out entityPropertyName)) { self._OnPropertyChanged(entityPropertyName); } } // Walk the entity tree from this point up to the root, raising // the [EntityChanged] events at every level. var node = this; while (true) { node.self._OnChanged(); if (node.parent == null) { break; } node = (DynamicEntity)node.parent; } }
/// <inheritdoc/> public bool Load(JProperty newProperty, bool reload = false) { Covenant.Requires <ArgumentNullException>(newProperty != null); var changed = !NeonHelper.JTokenEquals(property, newProperty); this.property = newProperty; this.entityValue = null; // Purge any cached entity info this.isDeletedFunc = null; if (reload && changed) { parentEntity._OnPropertyChanged(PropertyName); } return(changed); }
/// <inheritdoc/> public bool Load(JProperty newProperty, bool reload = false) { Covenant.Requires <ArgumentNullException>(newProperty != null); var changed = !NeonHelper.JTokenEquals(property, newProperty); NeonHelper.JTokenEquals(property, newProperty); property = newProperty; if (reload && changed) { parentEntity._OnPropertyChanged(PropertyName); } return(changed); }