Simplified property pattern matching expression for nested properties #4114
Replies: 4 comments 7 replies
-
This is not really the same though (though i can perceive how we could bend it to be the same). Specifically, Now, we could consider that in a pattern context it would mean 'non-null'. I certainly think there is merit to this idea, and the savings are significant. |
Beta Was this translation helpful? Give feedback.
-
Duplicate of #480 I think That said, On the other hand, if you really want to consider |
Beta Was this translation helpful? Give feedback.
-
Are we going to accept |
Beta Was this translation helpful? Give feedback.
-
If this goes ahead we should probably do the same for object initializers: var foo = new Foo
{
Bar.Baz = { 1 ,2, 3},
Goo.X = 42,
}; Equivalent to: var foo = new Foo
{
Bar = { Baz = { 1 ,2, 3 } },
Goo = { X = 42 } ,
}; Related is the (more complex) case of withers: #77 |
Beta Was this translation helpful? Give feedback.
-
Yesterday I stumbled upon a scenario where I needed to inspect a few properties on a given "response" object and respond to them accordingly. The problem was that some of the properties were nested multiple levels deep into the object graph, while others were in the root of the object.
This is an example:
As you can see, it becomes very unwieldy very fast when deep nesting levels are required in the matches.
I'd like to propose something like this instead:
At a first glance, it seems like an easy to implement syntactic sugar that doesn't appear to create any conflicts with existing language terms, as it relies on the
.
for navigation on something that doesn't support it today.While incredibly convoluted, this example is actually closely based on a real use-case on my side, as I had to deal with several possible outcomes happening from a single external service response. I believe the service itself is not that well designed, but that's beside the point.
Beta Was this translation helpful? Give feedback.
All reactions