/// <summary> /// Sets the value of the model content associated to this <see cref="GraphNodeViewModel"/>. The value is actually modified only if the new value is different from the previous value. /// </summary> /// <returns><c>True</c> if the value has been modified, <c>false</c> otherwise.</returns> protected virtual bool SetModelContentValue(IContentNode node, object newValue) { var oldValue = node.Retrieve(Index); if (!Equals(oldValue, newValue)) { node.Update(newValue, Index); return(true); } return(false); }
protected static bool UpdateCollection(IContentNode node, object value, Index index) { if (IsIndexExisting(node, index)) { node.Update(value, index); return(true); } if (IsIndexValid(node, index)) { node.Add(value, index); return(true); } return(false); }
public override Task Execute(IContentNode content, Index index, object parameter) { var hasIndex = content.Indices == null || content.Indices.Contains(index); var currentValue = hasIndex ? content.Retrieve(index) : (content.Type.IsValueType ? Activator.CreateInstance(content.Type) : null); var newValue = ChangeValue(currentValue, parameter); if (hasIndex) { if (!Equals(newValue, currentValue)) { content.Update(newValue, index); } } else { content.Add(newValue, index); } return(Task.FromResult(0)); }