mirror of
https://github.com/github/codeql.git
synced 2026-05-02 20:25:13 +02:00
C#: Add some examples with the extended property pattern syntax.
This commit is contained in:
56
csharp/ql/test/library-tests/csharp10/PropertyPatterns.cs
Normal file
56
csharp/ql/test/library-tests/csharp10/PropertyPatterns.cs
Normal file
@@ -0,0 +1,56 @@
|
||||
using System;
|
||||
|
||||
public record Point(int X, int Y);
|
||||
public record Line(Point P1, Point P2);
|
||||
public record Wrap(Line L);
|
||||
|
||||
public class PropertyPatterns
|
||||
{
|
||||
private static Line l = new Line(new Point(1, 2), new Point(3, 6));
|
||||
private static Wrap w = new Wrap(l);
|
||||
|
||||
public void M1()
|
||||
{
|
||||
if (l is { P1: { X: 1 } })
|
||||
{
|
||||
}
|
||||
|
||||
if (l is { P1.X: 2 })
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public void M2()
|
||||
{
|
||||
if (w is { L: { P2: { Y: 3 } } })
|
||||
{
|
||||
}
|
||||
|
||||
if (w is { L.P2.Y: 4 })
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public void M3()
|
||||
{
|
||||
if (w is { L: { P2.Y: 5 } })
|
||||
{
|
||||
}
|
||||
|
||||
if (w is { L.P2: { Y: 6 } })
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public void M4()
|
||||
{
|
||||
if (l is { P1: { X: 7 }, P1: { Y: 8 } })
|
||||
{
|
||||
}
|
||||
|
||||
if (l is { P1.X: 9, P1.Y: 10 })
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
recordTypes
|
||||
| PropertyPatterns.cs:3:1:3:34 | Point |
|
||||
| PropertyPatterns.cs:4:1:4:39 | Line |
|
||||
| PropertyPatterns.cs:5:1:5:27 | Wrap |
|
||||
| RecordTypes.cs:3:1:6:2 | MyEntry |
|
||||
| RecordTypes.cs:8:1:8:53 | MyClassRecord |
|
||||
| RecordTypes.cs:10:1:10:70 | MyReadonlyRecordStruct |
|
||||
@@ -9,5 +12,8 @@ recordStructs
|
||||
| RecordTypes.cs:12:1:12:51 | MyRecordStruct1 |
|
||||
| WithExpression.cs:9:1:9:47 | MyRecordStruct2 |
|
||||
recordClass
|
||||
| PropertyPatterns.cs:3:1:3:34 | Point |
|
||||
| PropertyPatterns.cs:4:1:4:39 | Line |
|
||||
| PropertyPatterns.cs:5:1:5:27 | Wrap |
|
||||
| RecordTypes.cs:3:1:6:2 | MyEntry |
|
||||
| RecordTypes.cs:8:1:8:53 | MyClassRecord |
|
||||
|
||||
Reference in New Issue
Block a user