private void PropagateChanges() { if (Targets.Count == 1 || Changes.Count == 0) { return; } var visitor = new PropertyPathVisitor(Changes); var target = Targets[0]; target.Visit(visitor); Changes.Clear(); var paths = visitor.GetPropertyPaths(); foreach (var path in paths) { // Get the value from the edited property. var resolution = path.Resolve(target); if (false == resolution.success) { continue; } var value = resolution.value; // And propagate to the other properties. for (var i = 1; i < Targets.Count; ++i) { var otherTarget = Targets[i]; var otherResolution = path.Resolve(otherTarget); if (false == otherResolution.success) { continue; } // TODO: not sure if this works in nested struct containers otherResolution.property.SetObjectValue(otherResolution.container, value); } } }
protected bool HasMixedValues <TValue>(IPropertyContainer container, IProperty property) { if (Targets.Count == 1) { return(false); } // Check the actual mixed value. var visitor = new PropertyPathVisitor(new PropertyPathContext { Container = container, Property = property }); var target = Targets[0]; var targetValue = (TValue)property.GetObjectValue(container); target.Visit(visitor); var paths = visitor.GetPropertyPaths(); if (paths.Count == 0) { //throw new Exception($"{UTinyConstants.ApplicationName}: Trying to get a property path for a property that is not part of the targets"); } for (var i = 1; i < Targets.Count; ++i) { var t = Targets[i]; var resolution = paths[0].Resolve(t); if (resolution.success == false) { continue; } var value = resolution.value; if (ValuesAreDifferent(value, targetValue)) { return(true); } } return(false); }