File tree Expand file tree Collapse file tree
lib/semmle/code/csharp/commons
src/utils/model-generator Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11/** Provides classes for collections. */
22
33import csharp
4+ import semmle.code.csharp.frameworks.system.Collections
5+ import semmle.code.csharp.frameworks.system.collections.Generic
46
57private string modifyMethodName ( ) {
68 result =
@@ -66,15 +68,13 @@ class CollectionType extends RefType {
6668 }
6769}
6870
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+ )
7878}
7979
8080/** 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) {
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-
7873private string parameterAccess ( Parameter p ) {
7974 if
80- isContainerType ( p .getType ( ) ) and
75+ isCollectionType ( p .getType ( ) ) and
8176 not isPrimitiveTypeUsedForBulkData ( p .getType ( ) .( ArrayType ) .getElementType ( ) )
8277 then result = "Argument[" + p .getPosition ( ) + "].Element"
8378 else result = "Argument[" + p .getPosition ( ) + "]"
You can’t perform that action at this time.
0 commit comments