File tree Expand file tree Collapse file tree 2 files changed +10
-15
lines changed
lib/semmle/code/csharp/commons
src/utils/model-generator Expand file tree Collapse file tree 2 files changed +10
-15
lines changed Original file line number Diff line number Diff line change 1
1
/** Provides classes for collections. */
2
2
3
3
import csharp
4
+ import semmle.code.csharp.frameworks.system.Collections
5
+ import semmle.code.csharp.frameworks.system.collections.Generic
4
6
5
7
private string modifyMethodName ( ) {
6
8
result =
@@ -66,15 +68,13 @@ class CollectionType extends RefType {
66
68
}
67
69
}
68
70
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
- }
71
+ /** Holds if `t` is a collection type. */
72
+ predicate isCollectionType ( ValueOrRefType t ) {
73
+ not t instanceof StringType and
74
+ exists ( ValueOrRefType base | base = t .getABaseType * ( ) |
75
+ base instanceof SystemCollectionsGenericIEnumerableTInterface or
76
+ base instanceof SystemCollectionsIEnumerableInterface
77
+ )
78
78
}
79
79
80
80
/** An object creation that creates an empty collection. */
Original file line number Diff line number Diff line change @@ -70,14 +70,9 @@ private predicate isPrimitiveTypeUsedForBulkData(Type t) {
70
70
t .getName ( ) .regexpMatch ( "byte|char|Byte|Char" )
71
71
}
72
72
73
- private predicate isContainerType ( Type t ) {
74
- t instanceof CollectionType or
75
- t instanceof IEnumerableType
76
- }
77
-
78
73
private string parameterAccess ( Parameter p ) {
79
74
if
80
- isContainerType ( p .getType ( ) ) and
75
+ isCollectionType ( p .getType ( ) ) and
81
76
not isPrimitiveTypeUsedForBulkData ( p .getType ( ) .( ArrayType ) .getElementType ( ) )
82
77
then result = "Argument[" + p .getPosition ( ) + "].Element"
83
78
else result = "Argument[" + p .getPosition ( ) + "]"
You can’t perform that action at this time.
0 commit comments