Skip to content

Commit 833e8e4

Browse files
committed
C#: Add some examples with the extended property pattern syntax.
1 parent 83e7fae commit 833e8e4

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
using System;
2+
3+
public record Point(int X, int Y);
4+
public record Line(Point P1, Point P2);
5+
public record Wrap(Line L);
6+
7+
public class PropertyPatterns
8+
{
9+
private static Line l = new Line(new Point(1, 2), new Point(3, 6));
10+
private static Wrap w = new Wrap(l);
11+
12+
public void M1()
13+
{
14+
if (l is { P1: { X: 1 } })
15+
{
16+
}
17+
18+
if (l is { P1.X: 2 })
19+
{
20+
}
21+
}
22+
23+
public void M2()
24+
{
25+
if (w is { L: { P2: { Y: 3 } } })
26+
{
27+
}
28+
29+
if (w is { L.P2.Y: 4 })
30+
{
31+
}
32+
}
33+
34+
public void M3()
35+
{
36+
if (w is { L: { P2.Y: 5 } })
37+
{
38+
}
39+
40+
if (w is { L.P2: { Y: 6 } })
41+
{
42+
}
43+
}
44+
45+
public void M4()
46+
{
47+
if (l is { P1: { X: 7 }, P1: { Y: 8 } })
48+
{
49+
}
50+
51+
if (l is { P1.X: 9, P1.Y: 10 })
52+
{
53+
}
54+
}
55+
}
56+

csharp/ql/test/library-tests/csharp10/recordTypes.expected

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
recordTypes
2+
| PropertyPatterns.cs:3:1:3:34 | Point |
3+
| PropertyPatterns.cs:4:1:4:39 | Line |
4+
| PropertyPatterns.cs:5:1:5:27 | Wrap |
25
| RecordTypes.cs:3:1:6:2 | MyEntry |
36
| RecordTypes.cs:8:1:8:53 | MyClassRecord |
47
| RecordTypes.cs:10:1:10:70 | MyReadonlyRecordStruct |
@@ -9,5 +12,8 @@ recordStructs
912
| RecordTypes.cs:12:1:12:51 | MyRecordStruct1 |
1013
| WithExpression.cs:9:1:9:47 | MyRecordStruct2 |
1114
recordClass
15+
| PropertyPatterns.cs:3:1:3:34 | Point |
16+
| PropertyPatterns.cs:4:1:4:39 | Line |
17+
| PropertyPatterns.cs:5:1:5:27 | Wrap |
1218
| RecordTypes.cs:3:1:6:2 | MyEntry |
1319
| RecordTypes.cs:8:1:8:53 | MyClassRecord |

0 commit comments

Comments
 (0)