I have a ReactiveUI-like view model. It has several properties of different types which fire NotifyPropertyChanged
events and I want to subscribe a method that will be called when any is fired, but I am not interested in actual values.
My current code is a bit ugly (due to opaque true
selects). Is there a way to express this which shows the intention of just caring when the event occurs?
this.ObservableForProperty(m => m.PropertyOne)
.Select(_ => true)
.Merge(this.ObservableForProperty(m => m.PropertyTwo).Select(_ => true))
.Subscribe(...)
I am merging about 8 properties, so it's more ugly than shown.
You could make it an extension method to make the intent clearer:
Since this looks like ReactiveUI, how about using the WhenAny operator:
In general though, if you were combining arbitrary Observables, you could also write this a bit more clearly using the non-extension method:
Also, if you're subscribing to every property of a ReactiveObject, it's probably better to just use: