Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 57c163f

Browse files
committed
C#: Add test for CIL setter extraction
1 parent 45893ab commit 57c163f

6 files changed

Lines changed: 36 additions & 0 deletions

File tree

csharp/ql/src/semmle/code/cil/Method.qll

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,9 @@ class Setter extends Accessor {
246246
Setter() { cil_setter(_, this) }
247247

248248
override Property getProperty() { cil_setter(result, this) }
249+
250+
/** Holds if this setter is an `init`-only accessor. */
251+
predicate isInitOnly() { none() }
249252
}
250253

251254
/**
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// semmle-extractor-options: --cil
2+
3+
using System;
4+
5+
class Test
6+
{
7+
static void Main(string[] args)
8+
{
9+
}
10+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
namespace System.Runtime.CompilerServices
2+
{
3+
class IsExternalInit { }
4+
}
5+
6+
namespace cil_init_prop
7+
{
8+
class SomeClass
9+
{
10+
public int Prop1 { get; set; }
11+
public int Prop2 { get; init; }
12+
}
13+
}
Binary file not shown.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
| cil-init-prop.dll:0:0:0:0 | set_Prop1 | set |
2+
| cil-init-prop.dll:0:0:0:0 | set_Prop2 | set |
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import semmle.code.cil.Method
2+
import semmle.code.csharp.Location
3+
4+
private string getType(Setter s) { if s.isInitOnly() then result = "init" else result = "set" }
5+
6+
from Setter s
7+
where s.getLocation().(Assembly).getName() = "cil-init-prop"
8+
select s, getType(s)

0 commit comments

Comments
 (0)