Skip to content

Commit 367bbc4

Browse files
committed
C#: Add some examples of using attributes on properties and indexers for use in external models.
1 parent 3c97bcb commit 367bbc4

File tree

2 files changed

+35
-6
lines changed

2 files changed

+35
-6
lines changed

csharp/ql/test/library-tests/dataflow/external-models/Sinks.cs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ void Foo()
1212

1313
object fieldWrite = new object();
1414
TaggedField = fieldWrite;
15+
16+
object propertyWrite = new object();
17+
TaggedPropertySetter = propertyWrite;
18+
19+
object indexerWrite = new object();
20+
this[0] = indexerWrite;
1521
}
1622

1723
object SinkMethod()
@@ -34,7 +40,21 @@ void TaggedSinkMethod(object x) { }
3440

3541
[SinkAttribute]
3642
object TaggedField;
43+
44+
[SinkPropertyAttribute]
45+
object TaggedPropertySetter { get; set; }
46+
47+
[SinkIndexerAttribute]
48+
object this[int index]
49+
{
50+
get { return null; }
51+
set { }
52+
}
3753
}
3854

3955
class SinkAttribute : System.Attribute { }
40-
}
56+
57+
class SinkPropertyAttribute : System.Attribute { }
58+
59+
class SinkIndexerAttribute : System.Attribute { }
60+
}

csharp/ql/test/library-tests/dataflow/external-models/Sources.cs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,17 @@ void Foo()
1818
x = TaggedSrcField;
1919

2020
x = SrcTwoArg("", "");
21+
22+
x = TaggedSrcPropertyGetter;
23+
x = this[0];
2124
}
2225

23-
[SourceAttribute()]
26+
[SourceAttribute]
2427
void Tagged1(object taggedMethodParam)
2528
{
2629
}
2730

28-
void Tagged2([SourceAttribute()] object taggedSrcParam)
31+
void Tagged2([SourceAttribute] object taggedSrcParam)
2932
{
3033
}
3134

@@ -49,14 +52,20 @@ public override void SrcParam(object p) { }
4952

5053
void SrcArg(object src) { }
5154

52-
[SourceAttribute()]
55+
[SourceAttribute]
5356
object TaggedSrcMethod() { return null; }
5457

55-
[SourceAttribute()]
58+
[SourceAttribute]
5659
object TaggedSrcField;
5760

5861
object SrcTwoArg(string s1, string s2) { return null; }
62+
63+
[SourceAttribute]
64+
object TaggedSrcPropertyGetter { get; }
65+
66+
[SourceAttribute]
67+
object this[int i] => null;
5968
}
6069

6170
class SourceAttribute : System.Attribute { }
62-
}
71+
}

0 commit comments

Comments
 (0)