Optional property assignment?

I've tried to do foo?.bar = value as a replacement for if (foo != null) foo.bar = value a plainly embarrassing number of times, forgetting that it's not actually a thing. Most commonly, it's when there's multiple levels of indirection like in foo?.bar?.baz = value where I forget, since foo?.bar?.baz is a valid expression to read, and (foo?.bar).baz = value is also a valid assignment.

Could optional assignment be added to 1. provide the same convenience available to property reads and 2. remove a clear syntactic gotcha I've been experiencing in practice?

Proposal for this is currently stage 1

2 Likes

Oh crap, forgot that was a thing. I'm normally better at catching new stage 1 proposals. Thanks! :sweat_smile:

2 Likes