mirror of
https://github.com/github/codeql.git
synced 2026-04-30 03:05:15 +02:00
C#: Introduce a collectionType predicate.
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
/** Provides classes for collections. */
|
||||
|
||||
import csharp
|
||||
import semmle.code.csharp.frameworks.system.Collections
|
||||
import semmle.code.csharp.frameworks.system.collections.Generic
|
||||
|
||||
private string modifyMethodName() {
|
||||
result =
|
||||
@@ -66,15 +68,13 @@ class CollectionType extends RefType {
|
||||
}
|
||||
}
|
||||
|
||||
/** An IEnumerable type. */
|
||||
class IEnumerableType extends RefType {
|
||||
IEnumerableType() {
|
||||
this.hasQualifiedName("System.Collections", "IEnumerable")
|
||||
or
|
||||
this.(ConstructedType)
|
||||
.getUnboundGeneric()
|
||||
.hasQualifiedName("System.Collections.Generic", "IEnumerable<>")
|
||||
}
|
||||
/** Holds if `t` is a collection type. */
|
||||
predicate isCollectionType(ValueOrRefType t) {
|
||||
not t instanceof StringType and
|
||||
exists(ValueOrRefType base | base = t.getABaseType*() |
|
||||
base instanceof SystemCollectionsGenericIEnumerableTInterface or
|
||||
base instanceof SystemCollectionsIEnumerableInterface
|
||||
)
|
||||
}
|
||||
|
||||
/** An object creation that creates an empty collection. */
|
||||
|
||||
@@ -70,14 +70,9 @@ private predicate isPrimitiveTypeUsedForBulkData(Type t) {
|
||||
t.getName().regexpMatch("byte|char|Byte|Char")
|
||||
}
|
||||
|
||||
private predicate isContainerType(Type t) {
|
||||
t instanceof CollectionType or
|
||||
t instanceof IEnumerableType
|
||||
}
|
||||
|
||||
private string parameterAccess(Parameter p) {
|
||||
if
|
||||
isContainerType(p.getType()) and
|
||||
isCollectionType(p.getType()) and
|
||||
not isPrimitiveTypeUsedForBulkData(p.getType().(ArrayType).getElementType())
|
||||
then result = "Argument[" + p.getPosition() + "].Element"
|
||||
else result = "Argument[" + p.getPosition() + "]"
|
||||
|
||||
Reference in New Issue
Block a user