[Proposal]: nested members in with
and object creation
#9002
Replies: 3 comments
-
Existing discussion on nested Could there be names in scope to avoid doing a deep traversal twice? A common scenario (usually deeper): // Names in scope after '=': NestedThing, Collection
thing = thing with { NestedThing.Collection = Collection.Remove(value) }; As opposed to: thing = thing with { NestedThing.Collection = thing.NestedThing.Collection.Remove(value) }; |
Beta Was this translation helpful? Give feedback.
-
Here's another potential alternate syntax: methodCallExpression with
{
Method with { Name = "MethodName" }
} |
Beta Was this translation helpful? Give feedback.
-
I hacked together my own Lenses with source generators today just to avoid annoying nested |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
nested members in
with
and object creationChampion issue: #9003
Summary
If we go ahead and add support for extended names in property patterns (
if (e is MethodCallExpression { Method.Name: "MethodName" })
), it makes sense for symmetry to allow this inwith
and object creation expressions:methodCallExpression with { Method.Name = "MethodName" }
new MethodCallExpression(...) { Method.Name = "MethodName" }
Motivation
This is particularly useful in the
with
expression, so you don't have to write:methodCallExpression with { Method = methodCallExpression.Method with { Name = "MethodName" } }
Detailed design
Drawbacks
Alternatives
Unresolved questions
Design meetings
Beta Was this translation helpful? Give feedback.
All reactions