1

Closed

Enhance ViewModelBase.Set/ObservableObject.Set

description

Can we have Set<T> return true|false depending on whether an event was raised or not?

e.g.
    protected bool Set<T>(
        Expression<Func<T>> propertyExpression,
        ref T field,
        T newValue,
        bool broadcast)
    {
        if (EqualityComparer<T>.Default.Equals(field, newValue))
        {
            return false;
        }

        var oldValue = field;
        field = newValue;
        RaisePropertyChanged(propertyExpression, oldValue, field, broadcast);

        return true;
    }
Then we can write code like:
    if( Set("AProperty", ref _aProperty, value) ){
        RaisePropertyChanged("_readonlyDerivedFromAProperty");
    }
Closed Oct 13, 2014 at 1:56 PM by lbugnion

comments