Luc Morin
Luc Morin

Reputation: 5380

How to use WhenAnyValue with more properties

The WhenAnyValue method is overloaded for up to 12 properties.

What is the recommended way of handling an arbitrarily large number of properties, more than can be handled by the defined overloads of WhenAnyValue?

Thanks

Upvotes: 2

Views: 3105

Answers (1)

Taylor Buchanan
Taylor Buchanan

Reputation: 4756

If you really must handle that many properties at once (omg, why?), I would suggest breaking up the properties into multiple calls to WhenAnyValue and combining them with CombineLatest. Since you're combining them all with WhenAnyValue anyway, I imagine this should work fine.

Example:

var group1 = this.WhenAnyValue(@this => @this.Prop1, ..., (prop1, ...) => ...);
var group2 = this.WhenAnyValue(@this => @this.Prop13, ..., (prop13, ...) => ...);
group1.CombineLatest(group2, (g1, g2) => ...);

WhenAnyValue just uses CombineLatest under the hood anyway.

Alternatively, you could create additional overloads to support more values. There isn't really a limit on the number of type parameters.

Upvotes: 4

Related Questions