Closed DavidArno closed 7 years ago
Unfortunately, it turns out that this change isn't possible with C# 7.1. Whilst the example in the OP would work, something like:
(a:1, b:1).Match().To<bool>
.With(1, __).Do(t => t.a ...
won't work. The type returned by Match
has to be T
, not (T1, T2)
. Using the latter (to enable wildcard support and to constrain the matcher to tuples) means that the item names are still lost, as they are for all tuple expressions in C# 7.
See this comment on the C# language repo for details.
Closing this issue therefore as there's no real solution to this yet.
Currently, pattern matching on eg
(1, 2)
just uses aMatcher<T1, T2, TResult>
matcher, forcing the tuple to be decomposed and supplying the two elements as separate parameters toWhere
andDo
.With C# 7.1, and its Inferred tuple names feature this becomes even more of an issue as it ought to be possible to do, eg:
The pattern matching of value tuples needs a rewrite to use a tuple-specific pattern matcher to enable such functionality.