Skip to content

Commit 36d8678

Browse files
authored
Merge pull request github#13588 from github/koesie10/update-csharp-external-api-name
C#: Fix external API name for nested types
2 parents 2c99009 + e4d2c51 commit 36d8678

File tree

4 files changed

+25
-2
lines changed

4 files changed

+25
-2
lines changed

csharp/ql/src/Telemetry/ExternalApi.qll

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class ExternalApi extends DotNet::Callable {
5050
bindingset[this]
5151
private string getSignature() {
5252
result =
53-
this.getDeclaringType().getUnboundDeclaration() + "." + this.getName() + "(" +
53+
nestedName(this.getDeclaringType().getUnboundDeclaration()) + "." + this.getName() + "(" +
5454
parameterQualifiedTypeNamesToString(this) + ")"
5555
}
5656

@@ -118,6 +118,21 @@ class ExternalApi extends DotNet::Callable {
118118
}
119119
}
120120

121+
/**
122+
* Gets the nested name of the declaration.
123+
*
124+
* If the declaration is not a nested type, the result is the same as \`getName()\`.
125+
* Otherwise the name of the nested type is prefixed with a \`+\` and appended to
126+
* the name of the enclosing type, which might be a nested type as well.
127+
*/
128+
private string nestedName(Declaration declaration) {
129+
not exists(declaration.getDeclaringType().getUnboundDeclaration()) and
130+
result = declaration.getName()
131+
or
132+
nestedName(declaration.getDeclaringType().getUnboundDeclaration()) + "+" + declaration.getName() =
133+
result
134+
}
135+
121136
/**
122137
* Gets the limit for the number of results produced by a telemetry query.
123138
*/

csharp/ql/test/query-tests/Telemetry/LibraryUsage/ExternalLibraryUsage.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,10 @@ public void M3()
2525
{
2626
var guid1 = Guid.Parse("{12345678-1234-1234-1234-123456789012}"); // Has no flow summary
2727
}
28+
29+
public void M4()
30+
{
31+
var d = new Dictionary<string, object>(); // Uninteresting parameterless constructor
32+
var e = d.Keys.GetEnumerator().MoveNext(); // Methods on nested classes
33+
}
2834
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
| System | 5 |
2-
| System.Collections.Generic | 2 |
2+
| System.Collections.Generic | 5 |
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
| System.Collections.Generic#List<>.Add(T) | 2 |
2+
| System.Collections.Generic#Dictionary<,>+KeyCollection.GetEnumerator() | 1 |
3+
| System.Collections.Generic#Dictionary<,>.get_Keys() | 1 |

0 commit comments

Comments
 (0)