Skip to content

Commit ec6dab8

Browse files
committed
C#: Update the Summary model generator with better support for IEnumerable typed parameters.
1 parent 4f2678f commit ec6dab8

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

csharp/ql/lib/semmle/code/csharp/commons/Collections.qll

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,17 @@ class CollectionType extends RefType {
6666
}
6767
}
6868

69+
/** An IEnumerable type. */
70+
class IEnumerableType extends RefType {
71+
IEnumerableType() {
72+
this.hasQualifiedName("System.Collections", "IEnumerable")
73+
or
74+
this.(ConstructedType)
75+
.getUnboundGeneric()
76+
.hasQualifiedName("System.Collections.Generic", "IEnumerable<>")
77+
}
78+
}
79+
6980
/** An object creation that creates an empty collection. */
7081
class EmptyCollectionCreation extends ObjectCreation {
7182
EmptyCollectionCreation() {

csharp/ql/src/utils/model-generator/ModelGeneratorUtilsSpecific.qll

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,14 @@ private predicate isPrimitiveTypeUsedForBulkData(Type t) {
7070
t.getName().regexpMatch("byte|char|Byte|Char")
7171
}
7272

73+
private predicate isContainerType(Type t) {
74+
t instanceof CollectionType or
75+
t instanceof IEnumerableType
76+
}
77+
7378
private string parameterAccess(Parameter p) {
7479
if
75-
p.getType() instanceof CollectionType and
80+
isContainerType(p.getType()) and
7681
not isPrimitiveTypeUsedForBulkData(p.getType().(ArrayType).getElementType())
7782
then result = "Argument[" + p.getPosition() + "].Element"
7883
else result = "Argument[" + p.getPosition() + "]"

0 commit comments

Comments
 (0)