Skip to content

Commit 05c3b5c

Browse files
RexJaeschkeBillWagner
authored andcommitted
support extended property patterns
1 parent c94dac8 commit 05c3b5c

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

standard/patterns.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,11 @@ subpatterns
211211
;
212212
subpattern
213213
: pattern
214-
| identifier ':' pattern
214+
| subpattern_name ':' pattern
215+
;
216+
subpattern_name
217+
: identifier
218+
| subpattern_name '.' identifier
215219
;
216220
```
217221

@@ -319,6 +323,12 @@ At runtime, the expression is tested against *T*. If this fails then the propert
319323
320324
The *property_pattern* may be used to pattern-match with anonymous types.
321325
326+
A *property_subpattern* may reference a nested member. In such a case, the receiver for each name lookup is the type of the previous member *T₀*, starting from the *input type* of the *property_pattern*. If *T* is a nullable type, *T₀* is its underlying type, otherwise *T₀* is equal to *T*. For example, a pattern of the form `{ Prop1.Prop2: pattern }` is exactly equivalent to `{ Prop1: { Prop2: pattern } }`.
327+
328+
> *Note*: This will include the null check when *T* is a nullable value type or a reference type. This null check means that the nested properties available will be the properties of *T₀*, not of *T*. As repeated member paths are allowed, the compilation of pattern matching can take advantage of common parts of patterns. *end note*
329+
<!-- markdownlint-disable MD028 -->
330+
331+
<!-- markdownlint-enable MD028 -->
322332
> *Example*:
323333
>
324334
> <!-- Example: {template:"standalone-console", name:"PropertyPattern2", replaceEllipsis:true, customEllipsisReplacements: ["new object()", ";"], ignoredWarnings:["CS0642"]} -->

0 commit comments

Comments
 (0)