protected override void StartListeningCore(WeakReference <object> reference) { reference.TryGetTarget(out object target); IPropertyAccessorPlugin plugin = null; foreach (IPropertyAccessorPlugin x in ExpressionObserver.PropertyAccessors) { if (x.Match(target, PropertyName)) { plugin = x; break; } } var accessor = plugin?.Start(reference, PropertyName); // We need to handle accessor fallback before handling validation. Validators do not support null accessors. if (accessor == null) { reference.TryGetTarget(out object instance); var message = $"Could not find a matching property accessor for '{PropertyName}' on '{instance}'"; var exception = new MissingMemberException(message); accessor = new PropertyError(new BindingNotification(exception, BindingErrorType.Error)); } if (_enableValidation && Next == null) { foreach (var validator in ExpressionObserver.DataValidators) { if (validator.Match(reference, PropertyName)) { accessor = validator.Start(reference, PropertyName, accessor); } } } if (accessor is null) { throw new AvaloniaInternalException("Data validators must return non-null accessor."); } _accessor = accessor; accessor.Subscribe(ValueChanged); }
protected override void StartListeningCore(WeakReference <object> reference) { reference.TryGetTarget(out object target); IPropertyAccessorPlugin plugin = null; foreach (IPropertyAccessorPlugin x in ExpressionObserver.PropertyAccessors) { if (x.Match(target, PropertyName)) { plugin = x; break; } } var accessor = plugin?.Start(reference, PropertyName); if (_enableValidation && Next == null) { foreach (var validator in ExpressionObserver.DataValidators) { if (validator.Match(reference, PropertyName)) { accessor = validator.Start(reference, PropertyName, accessor); } } } if (accessor == null) { reference.TryGetTarget(out object instance); var message = $"Could not find a matching property accessor for '{PropertyName}' on '{instance}'"; var exception = new MissingMemberException(message); accessor = new PropertyError(new BindingNotification(exception, BindingErrorType.Error)); } _accessor = accessor; accessor.Subscribe(ValueChanged); }
protected override void StartListeningCore(WeakReference <object> reference) { reference.TryGetTarget(out object target); IPropertyAccessorPlugin plugin = null; foreach (IPropertyAccessorPlugin x in ExpressionObserver.PropertyAccessors) { if (x.Match(target, PropertyName)) { plugin = x; break; } } var accessor = plugin?.Start(reference, PropertyName); if (_enableValidation && Next == null) { foreach (var validator in ExpressionObserver.DataValidators) { if (validator.Match(reference, PropertyName)) { accessor = validator.Start(reference, PropertyName, accessor); } } } if (accessor == null) { throw new NotSupportedException( $"Could not find a matching property accessor for {PropertyName}."); } _accessor = accessor; accessor.Subscribe(ValueChanged); }
public PropertyAccessorNode(string propertyName, bool enableValidation, IPropertyAccessorPlugin customPlugin) { PropertyName = propertyName; _enableValidation = enableValidation; _customPlugin = customPlugin; }