/// <summary> /// Notifies other properties of a view model if listener raises event. /// </summary> /// <typeparam name="T">Type of the property to notify.</typeparam> /// <param name="listener">The listener to monitor.</param> /// <param name="expression">The expression of the notify target property.</param> /// <returns>The listener itself for chaining.</returns> /// <exception cref="InvalidOperationException">If Expression is not an member expression.</exception> public static IPropertyListener Notify <T>(this IPropertyListener listener, Expression <Func <T> > expression) { if (expression.Body.NodeType != ExpressionType.MemberAccess || !(expression.Body is MemberExpression me)) { throw new InvalidOperationException($"Expression must point to an Property of an view model of type {nameof(IViewModel)}."); } var propertyName = me.Member.Name; var obj = Expression.Lambda(me.Expression).Compile().DynamicInvoke(); bool success = false; if (obj is IViewModel viewModel) { listener.PropertyChanged += (s, a) => { viewModel.OnPropertyChanged(propertyName); }; success = true; } if (typeof(ICommand).IsAssignableFrom(typeof(T))) { Func <T> getter = expression.Compile(); listener.PropertyChanged += (s, a) => { if (getter() is INotifyCommand command) { command.NotifyCanExecuteChanged(); } }; success = true; } if (!success) { throw new InvalidOperationException("Property does not belong to an IViewModel and is not a ICommand"); } return(listener); }
public static IObserver <object> Observer(this IPropertyListener listener, string name) { return(listener.Observer(name)); }
public static IObserver <T> Observer <T>(this IPropertyListener listener, string?name = null) { return(listener.Observer <T>(name)); }
public Property(T value, IPropertyListener listener) { this._value = value; this.listener = listener; }
public Property(string name, IPropertyListener <T> listener, T initialValue) { _Name = name; _listener = listener; _underlying = initialValue; }
/// <summary> /// Adds an callback to an listener. /// </summary> /// <param name="listener">Listener to extend.</param> /// <param name="action">The action to perform on property changed.</param> /// <returns>The listener itself for chaining.</returns> public static IPropertyListener Call(this IPropertyListener listener, Action action) { listener.PropertyChanged += (s, a) => action(); return(listener); }
public void AddListener(IPropertyListener listener) { this.AddListenerRaised?.Invoke(this, listener); }
public void AddListener(IPropertyListener listener) { }