|
2 | 2 |
|
3 | 3 | import csharp |
4 | 4 | import semmle.code.csharp.frameworks.system.Collections |
| 5 | +private import semmle.code.csharp.frameworks.System |
| 6 | +private import semmle.code.csharp.frameworks.system.collections.Generic |
5 | 7 |
|
6 | 8 | private string modifyMethodName() { |
7 | 9 | result = |
@@ -67,6 +69,42 @@ class CollectionType extends RefType { |
67 | 69 | } |
68 | 70 | } |
69 | 71 |
|
| 72 | +/** |
| 73 | + * A collection type that can be used as a `params` parameter type. |
| 74 | + */ |
| 75 | +abstract private class ParamsCollectionTypeImpl extends ValueOrRefType { |
| 76 | + /** |
| 77 | + * Gets the element type of this collection, for example `int` in `IEnumerable<int>`. |
| 78 | + */ |
| 79 | + abstract Type getElementType(); |
| 80 | +} |
| 81 | + |
| 82 | +private class ParamsArrayType extends ParamsCollectionTypeImpl instanceof ArrayType { |
| 83 | + override Type getElementType() { result = ArrayType.super.getElementType() } |
| 84 | +} |
| 85 | + |
| 86 | +private class ParamsConstructedCollectionTypes extends ParamsCollectionTypeImpl { |
| 87 | + private ConstructedType base; |
| 88 | + |
| 89 | + ParamsConstructedCollectionTypes() { |
| 90 | + exists(UnboundGenericType unboundbase | |
| 91 | + base = this.getABaseType*() and unboundbase = base.getUnboundGeneric() |
| 92 | + | |
| 93 | + unboundbase instanceof SystemCollectionsGenericIEnumerableTInterface or |
| 94 | + unboundbase instanceof SystemCollectionsGenericICollectionInterface or |
| 95 | + unboundbase instanceof SystemCollectionsGenericIListTInterface or |
| 96 | + unboundbase instanceof SystemCollectionsGenericIReadOnlyCollectionTInterface or |
| 97 | + unboundbase instanceof SystemCollectionsGenericIReadOnlyListTInterface or |
| 98 | + unboundbase instanceof SystemSpanStruct or |
| 99 | + unboundbase instanceof SystemReadOnlySpanStruct |
| 100 | + ) |
| 101 | + } |
| 102 | + |
| 103 | + override Type getElementType() { result = base.getTypeArgument(0) } |
| 104 | +} |
| 105 | + |
| 106 | +final class ParamsCollectionType = ParamsCollectionTypeImpl; |
| 107 | + |
70 | 108 | /** Holds if `t` is a collection type. */ |
71 | 109 | predicate isCollectionType(ValueOrRefType t) { |
72 | 110 | t.getABaseType*() instanceof SystemCollectionsIEnumerableInterface and |
|
0 commit comments