✅ `with` expression does not work with `ValueTuple`
This code:
Gives
The name 'Bar' does not exist in the current context
on the second line? Why is this?6 Replies
Bar
is a field, not a property
I assume with
expressions only work with properties...?
Or wait might be that you can't set tuple values like thatWith expressions do not allow setting nested values
Probably because if
Bar
is a reference type, then with
becomes destructive, which is not what it promisesNot really, we didn't allow it because we don't find it clear
In this particular example, it's probably ok, but in general we didn't think so
There are proposals around enhancements, but they also run into the issue of understandablility
You could probably do
foo with { Bar = foo.Bar with { Item1 = 1 } }
...?I can