Tobi
Tobi

Reputation: 183

WhenAny for current null values

Is there any way to use WhenAny for the property of a value that is currently null and will be set later?
Like this:

public Server SelectedServer {get;set;}

public TestClass()
{
    this.WhenAny(SelectedServer.Items.Changed, x => x).Subscribe(/*Do something*/);
}  

SelectedServer is initially null, will be set by through user interaction and therefor I always get a NullReferenceException in the Constructor.

Upvotes: 1

Views: 1484

Answers (1)

Ana Betts
Ana Betts

Reputation: 74654

This is a typo that instead produces a runtime crash, it should be:

this.WhenAnyValue(x => x.SelectedServer.Items.Changed);

But given the name of your variable, I'm guessing a better thing would be:

this.WhenAnyObservable(x => x.SelectedServer.Items.Changed);

Upvotes: 2

Related Questions