public ParameterListener(ParameterCollection parameterCollection, ParameterPath path) { this.path = path; foreach (var currentContainer in ContainersInPath(parameterCollection, path.Keys)) { AppendCurrentPath(currentContainer); } currentValue = path.GetValue(containers[0].Value); }
public ParameterListener(ParameterCollection parameterCollection, ParameterPath path) { this.path = path; foreach (var currentContainer in ContainersInPath(parameterCollection, path.Keys)) { AppendCurrentPath(currentContainer); } currentValue = path.GetValue(containers[0].Value); }
private void propertyContainer_PropertyUpdated(ParameterCollection parameterCollection, object newValue, object oldValue, int pathIndex) { if (containers[pathIndex].Value != parameterCollection) { throw new InvalidOperationException("Unexpected PropertyContainer in PathListener."); } // Optimize case where last item only changed (no need to recreate subpath) if (pathIndex < path.Keys.Length - 1) { // Unregister listeners of this subpath for (int i = pathIndex + 1; i < containers.Count; ++i) { // Only remove event handler if not present in first part of the path (otherwise we need to keep it) if (containers.IndexOf(containers[i], 0, i) == -1) { containers[i].Value.RemoveEvent(path.Keys[i], delegates[i]); } } // Remove containers of this subpath containers.RemoveRange(pathIndex + 1, containers.Count - pathIndex - 1); delegates.RemoveRange(pathIndex + 1, delegates.Count - pathIndex - 1); // Recreate subpath hierarchy foreach (var currentContainer in ContainersInPath(parameterCollection, path.Keys.Skip(pathIndex)).Skip(1)) { // Only add event handler if not already in the path (if same PropertyContainer is multiple time in the path) AppendCurrentPath(currentContainer); } } var newValue2 = path.GetValue(containers[0].Value); if (ParameterUpdated != null && !ArePropertyValuesEqual(path.Keys.Last(), this.currentValue, newValue2)) { ParameterUpdated(containers[0].Value, path, newValue2); } this.currentValue = newValue2; }