Sorry I couldn't think of a better title. This is a two part question that only make sense together.
Say I have a constructor like this
public Fact(INotifyPropertyChanged observable, Func<bool> predicate)
{
this.predicate = predicate;
observable.PropertyChanged += (sender, args) =>
PropertyChanged(this, new PropertyChangedEventArgs("Value"));
}
and this is how it's used
new Fact(Model.AllowEditing, () => Model.AllowEditing);
where AllowEditing is a type of INotifyPropertyChanged
I would like to refactor the constructor into
public Fact(Expression<Func<bool>> expression)
So it can be call like this
new Fact(() => Model.AllowEditing);
The question is how to parse that expression to get "observable" out of the expression tree then subscribe to its event?
The code above is not mine, it come from an example recent example from Ayende, here is the like to the full source code if anyone want to take a look of how the Fact class is being used http://github.com/ayende/Effectus