How to cast inside WhenAnyValue
expression?
#3727
Answered
by
anaisbetts
sinatrocious
asked this question in
Q&A
-
I need to cast inside this.WhenAnyValue(vm => (vm.Foo as Bar)!.Property) But I am getting
Show full exception details
Am I missing something obvious, doing something wrong or is there a good workaround? I was using something weird and likely memory leaking: this.WhenAnyValue(vm => vm.Foo).Subscribe(foo =>
{
if(foo is Bar bar)
bar.WhenAnyValue(o => o!.Property).Subscribe(property => ExtraProperty = property);
}); But I can't use this approach anymore, because I need to pass resulting |
Beta Was this translation helpful? Give feedback.
Answered by
anaisbetts
Feb 7, 2024
Replies: 1 comment 3 replies
-
Not particularly elegant but if you really have to do the cast: this.WhenAnyValue(x => x.Foo)
.Select(x => x != null ? ((Bar)x).WhenAnyValue(y => y => Property) : Observable.Empty())
.Switch(); |
Beta Was this translation helpful? Give feedback.
3 replies
Answer selected by
sinatrocious
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Not particularly elegant but if you really have to do the cast: